Skip to content

Commit

Permalink
Merge pull request #558 from Bhashinee/versionUpdate
Browse files Browse the repository at this point in the history
Introduce the support for reading private/public keys from the content
  • Loading branch information
Bhashinee authored May 30, 2024
2 parents 29b9a9e + 173a82d commit 88c10ae
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 58 deletions.
25 changes: 25 additions & 0 deletions ballerina/private_public_key.bal
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ public isolated function decodeRsaPrivateKeyFromKeyFile(string keyFile, string?
'class: "io.ballerina.stdlib.crypto.nativeimpl.Decode"
} external;

# Decodes the RSA private key from the given private key content as a byte array.
# ```ballerina
# byte[] keyFileContent = [45,45,45,45,45,66,69,71,73,78,...];
# crypto:PrivateKey privateKey = check crypto:decodeRsaPrivateKeyFromContent(keyFileContent, "keyPassword");
# ```
#
# + keyFile - Private key content as a byte array
# + keyPassword - Password of the private key if it is encrypted
# + return - Reference to the private key or else a `crypto:Error` if the private key was unreadable
public isolated function decodeRsaPrivateKeyFromContent(byte[] content, string? keyPassword = ()) returns PrivateKey|Error = @java:Method {
'class: "io.ballerina.stdlib.crypto.nativeimpl.Decode"
} external;

# Decodes the EC private key from the given private key and private key password.
# ```ballerina
# string keyFile = "/path/to/private.key";
Expand Down Expand Up @@ -292,6 +305,18 @@ public isolated function decodeRsaPublicKeyFromCertFile(string certFile) returns
'class: "io.ballerina.stdlib.crypto.nativeimpl.Decode"
} external;

# Decodes the RSA public key from the given public certificate content.
# ```ballerina
# byte[] certContent = [45,45,45,45,45,66,69,71,73,78,...];
# crypto:PublicKey publicKey = check crypto:decodeRsaPublicKeyFromContent(certContent);
# ```
#
# + certFile - The certificate content as a byte array
# + return - Reference to the public key or else a `crypto:Error` if the public key was unreadable
public isolated function decodeRsaPublicKeyFromContent(byte[] content) returns PublicKey|Error = @java:Method {
'class: "io.ballerina.stdlib.crypto.nativeimpl.Decode"
} external;

# Decodes the EC public key from the given public certificate file.
# ```ballerina
# string certFile = "/path/to/public.cert";
Expand Down
Loading

0 comments on commit 88c10ae

Please sign in to comment.