Skip to content

Commit

Permalink
Implement the support for reading private/public keys from the content
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed May 29, 2024
1 parent a95dd18 commit cc4f114
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 28 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 cc4f114

Please sign in to comment.