Functions

buildRsaPublicKey
I

Returns the crypto:PublicKey created with the modulus and exponent retrieved from the JWK's endpoint.

crc32b
I

Returns the Hex-encoded CRC32B value for the provided element.

decodeRsaPrivateKeyFromKeyFile
I

Reads a private key from the provided private key and private key password.

decodeRsaPrivateKeyFromKeyStore
I

Reads a private key from the provided PKCS#12 archive file.

decodeRsaPublicKeyFromCertFile
I

Reads a public key from the provided public certificate file.

decodeRsaPublicKeyFromTrustStore
I

Reads a public key from the provided PKCS#12 archive file.

decryptAesCbc
I

Returns the AES-CBC-decrypted value for the given AES-CBC-encrypted data.

decryptAesEcb
I

Returns the AES-ECB-decrypted value for the given AES-ECB-encrypted data.

decryptAesGcm
I

Returns the AES-GCM-decrypted value for the given AES-GCM-encrypted data.

decryptRsaEcb
I

Returns the RSA-decrypted value for the given RSA-encrypted data.

encryptAesCbc
I

Returns the AES-CBC-encrypted value for the given data.

encryptAesEcb
I

Returns the AES-ECB-encrypted value for the given data.

encryptAesGcm
I

Returns the AES-GCM-encrypted value for the given data.

encryptRsaEcb
I

Returns the RSA-encrypted value for the given data.

hashMd5
I

Returns the MD5 hash of the given data.

hashSha1
I

Returns the SHA-1 hash of the given data.

hashSha256
I

Returns the SHA-256 hash of the given data.

hashSha384
I

Returns the SHA-384 hash of the given data.

hashSha512
I

Returns the SHA-512 hash of the given data.

hmacMd5
I

Returns the HMAC using the MD-5 hash function of the given data.

hmacSha1
I

Returns the HMAC using the SHA-1 hash function of the given data.

hmacSha256
I

Returns the HMAC using the SHA-256 hash function of the given data.

hmacSha384
I

Returns the HMAC using the SHA-384 hash function of the given data.

hmacSha512
I

Returns the HMAC using the SHA-512 hash function of the given data.

signRsaMd5
I

Returns the RSA-MD5-based signature value for the given data.

signRsaSha1
I

Returns the RSA-SHA1-based signature value for the given data.

signRsaSha256
I

Returns the RSA-SHA256-based signature value for the given data.

signRsaSha384
I

Returns the RSA-SHA384-based signature value for the given data.

signRsaSha512
I

Returns the RSA-SHA512-based signature value for the given data.

verifyRsaMd5Signature
I

Verifies the RSA-MD5-based signature.

verifyRsaSha1Signature
I

Verifies the RSA-SHA1-based signature.

verifyRsaSha256Signature
I

Verifies the RSA-SHA256-based signature.

verifyRsaSha384Signature
I

Verifies the RSA-SHA384-based signature.

verifyRsaSha512Signature
I

Verifies the RSA-SHA512-based signature.

buildRsaPublicKey

function buildRsaPublicKey(string modulus, string exponent) returns PublicKey | Error
Isolated Function

Returns the crypto:PublicKey created with the modulus and exponent retrieved from the JWK's endpoint.

1string modulus = "luZFdW1ynitztkWLC6xKegbRWxky...";
2string exponent = "AQAB";
3crypto:PublicKey|crypto:Error publicKey = crypto:buildRsaPublicKey(modulus, exponent);

Parameters

  • modulus string
  • JWK modulus value ('n' parameter) for the RSA public key

  • exponent string
  • JWK exponent value ('e' paramenter) for the RSA public key

Return Type

(PublicKey | Error)

Reference to the public key or else a crypto:Error if the modulus or exponent is invalid

crc32b

function crc32b(byte[ ] input) returns string
Isolated Function

Returns the Hex-encoded CRC32B value for the provided element.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string checksum = crypto:crc32b(data);

Parameters

  • input byte[ ]
  • Value for checksum generation

Return Type

(string)

The generated checksum

decodeRsaPrivateKeyFromKeyFile

function decodeRsaPrivateKeyFromKeyFile(string keyFile, string? keyPassword) returns PrivateKey | Error
Isolated Function

Reads a private key from the provided private key and private key password.

1 string keyFile = "/home/ballerina/private.key";
2 crypto:PrivateKey|crypto:Error privateKey = crypto:decodeRsaPrivateKeyFromKeyFile(keyFile, "keyPassword");

Parameters

  • keyFile string
  • Path to the key file

  • keyPassword string? (default ())
  • Password of the key file if it is encrypted

Return Type

(PrivateKey | Error)

Reference to the private key or else a crypto:Error if the private key was unreadable

decodeRsaPrivateKeyFromKeyStore

function decodeRsaPrivateKeyFromKeyStore(KeyStore keyStore, string keyAlias, string keyPassword) returns PrivateKey | Error
Isolated Function

Reads a private key from the provided PKCS#12 archive file.

1 crypto:KeyStore keyStore = {
2 path: "/home/ballerina/keystore.p12",
3 password: "keystorePassword"
4 };
5 crypto:PrivateKey|crypto:Error privateKey = crypto:decodeRsaPrivateKeyFromKeyStore(keyStore, "keyAlias", "keyPassword");

Parameters

  • keyStore KeyStore
  • KeyStore configurations

  • keyPassword string
  • Key password

Return Type

(PrivateKey | Error)

Reference to the private key or else a crypto:Error if the private key was unreadable

decodeRsaPublicKeyFromCertFile

function decodeRsaPublicKeyFromCertFile(string certFile) returns PublicKey | Error
Isolated Function

Reads a public key from the provided public certificate file.

1 string certFile = "/home/ballerina/public.cert";
2 crypto:PublicKey|crypto:Error publicKey = crypto:decodeRsaPublicKeyFromCertFile(certFile);

Parameters

  • certFile string
  • Path to the ceritificate file

Return Type

(PublicKey | Error)

Reference to the public key or else a crypto:Error if the public key was unreadable

decodeRsaPublicKeyFromTrustStore

function decodeRsaPublicKeyFromTrustStore(TrustStore trustStore, string keyAlias) returns PublicKey | Error
Isolated Function

Reads a public key from the provided PKCS#12 archive file.

1 crypto:TrustStore trustStore = {
2 path: "/home/ballerina/truststore.p12",
3 password: "truststorePassword"
4 };
5 crypto:PublicKey|crypto:Error publicKey = crypto:decodeRsaPublicKeyFromTrustStore(trustStore, "keyAlias");

Parameters

Return Type

(PublicKey | Error)

Reference to the public key or else a crypto:Error if the public key was unreadable

decryptAesCbc

function decryptAesCbc(byte[ ] input, byte[ ] key, byte[ ] iv, AesPadding padding) returns byte[ ] | Error
Isolated Function

Returns the AES-CBC-decrypted value for the given AES-CBC-encrypted data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[16] initialVector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
8 foreach var i in 0...15 {
9 initialVector[i] = <byte>(check random:createIntInRange(0, 255);
10 }
11 byte[] cipherText = check crypto:encryptAesCbc(data, key, initialVector);
12 byte[]|crypto:Error plainText = crypto:decryptAesCbc(cipherText, key, initialVector);

Parameters

  • input byte[ ]
  • The content to be decrypted

  • key byte[ ]
  • Encryption key

  • iv byte[ ]
  • Initialization vector

Return Type

(byte[ ] | Error)

Decrypted data or else a crypto:Error if the key is invalid

decryptAesEcb

function decryptAesEcb(byte[ ] input, byte[ ] key, AesPadding padding) returns byte[ ] | Error
Isolated Function

Returns the AES-ECB-decrypted value for the given AES-ECB-encrypted data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[] cipherText = check crypto:encryptAesEcb(data, key);
8 byte[]|crypto:Error plainText = crypto:decryptAesEcb(cipherText, key);

Parameters

  • input byte[ ]
  • The content to be decrypted

  • key byte[ ]
  • Encryption key

Return Type

(byte[ ] | Error)

Decrypted data or else a crypto:Error if the key is invalid

decryptAesGcm

function decryptAesGcm(byte[ ] input, byte[ ] key, byte[ ] iv, AesPadding padding, int tagSize) returns byte[ ] | Error
Isolated Function

Returns the AES-GCM-decrypted value for the given AES-GCM-encrypted data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[16] initialVector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
8 foreach var i in 0...15 {
9 initialVector[i] = <byte>(check random:createIntInRange(0, 255);
10 }
11 byte[] cipherText = check crypto:encryptAesGcm(data, key, initialVector);
12 byte[]|crypto:Error plainText = crypto:decryptAesGcm(cipherText, key, initialVector);

Parameters

  • input byte[ ]
  • The content to be decrypted

  • key byte[ ]
  • Encryption key

  • iv byte[ ]
  • Initialization vector

  • tagSize int (default 128)
  • Tag size

Return Type

(byte[ ] | Error)

Decrypted data or else a crypto:Error if the key is invalid

decryptRsaEcb

function decryptRsaEcb(byte[ ] input, PrivateKey | PublicKey key, RsaPadding padding) returns byte[ ] | Error
Isolated Function

Returns the RSA-decrypted value for the given RSA-encrypted data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
8 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
9 byte[] cipherText = check crypto:encryptRsaEcb(data, publicKey);
10 byte[]|crypto:Error plainText = check crypto:decryptRsaEcb(cipherText, privateKey);

Parameters

  • input byte[ ]
  • The content to be decrypted

Return Type

(byte[ ] | Error)

Decrypted data or else a crypto:Error if the key is invalid

encryptAesCbc

function encryptAesCbc(byte[ ] input, byte[ ] key, byte[ ] iv, AesPadding padding) returns byte[ ] | Error
Isolated Function

Returns the AES-CBC-encrypted value for the given data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[16] initialVector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
8 foreach var i in 0...15 {
9 initialVector[i] = <byte>(check random:createIntInRange(0, 255);
10 }
11 byte[]|crypto:Error cipherText = crypto:encryptAesCbc(data, key, initialVector);

Parameters

  • input byte[ ]
  • The content to be encrypted

  • key byte[ ]
  • Encryption key

  • iv byte[ ]
  • Initialization vector

Return Type

(byte[ ] | Error)

Encrypted data or else a crypto:Error if the key is invalid

encryptAesEcb

function encryptAesEcb(byte[ ] input, byte[ ] key, AesPadding padding) returns byte[ ] | Error
Isolated Function

Returns the AES-ECB-encrypted value for the given data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[]|crypto:Error cipherText = crypto:encryptAesEcb(data, key);

Parameters

  • input byte[ ]
  • The content to be encrypted

  • key byte[ ]
  • Encryption key

Return Type

(byte[ ] | Error)

Encrypted data or else a crypto:Error if the key is invalid

encryptAesGcm

function encryptAesGcm(byte[ ] input, byte[ ] key, byte[ ] iv, AesPadding padding, int tagSize) returns byte[ ] | Error
Isolated Function

Returns the AES-GCM-encrypted value for the given data.

1 string dataString = "Hello Ballerina!";
2 byte[] data = dataString.toBytes();
3 byte[16] key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4 foreach var i in 0...15 {
5 key[i] = <byte>(check random:createIntInRange(0, 255);
6 }
7 byte[16] initialVector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
8 foreach var i in 0...15 {
9 initialVector[i] = <byte>(check random:createIntInRange(0, 255);
10 }
11 byte[]|crypto:Error cipherText = crypto:encryptAesGcm(data, key, initialVector);

Parameters

  • input byte[ ]
  • The content to be encrypted

  • key byte[ ]
  • Encryption key

  • iv byte[ ]
  • Initialization vector

  • tagSize int (default 128)
  • Tag size

Return Type

(byte[ ] | Error)

Encrypted data or else a crypto:Error if the key is invalid

encryptRsaEcb

function encryptRsaEcb(byte[ ] input, PrivateKey | PublicKey key, RsaPadding padding) returns byte[ ] | Error
Isolated Function

Returns the RSA-encrypted value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
8 byte[]|crypto:Error cipherText = crypto:encryptRsaEcb(data, publicKey);

Parameters

  • input byte[ ]
  • The content to be encrypted

Return Type

(byte[ ] | Error)

Encrypted data or else a crypto:Error if the key is invalid

hashMd5

function hashMd5(byte[ ] input) returns byte[ ]
Isolated Function

Returns the MD5 hash of the given data.

1 string dataString = "Hello Ballerina";
2 byte[] data = dataString.toBytes();
3 byte[] hash = crypto:hashMd5(data);

Parameters

  • input byte[ ]
  • Value to be hashed

Return Type

(byte[ ])

Hashed output

hashSha1

function hashSha1(byte[ ] input) returns byte[ ]
Isolated Function

Returns the SHA-1 hash of the given data.

1 string dataString = "Hello Ballerina";
2 byte[] data = dataString.toBytes();
3 byte[] hash = crypto:hashSha1(data);

Parameters

  • input byte[ ]
  • Value to be hashed

Return Type

(byte[ ])

Hashed output

hashSha256

function hashSha256(byte[ ] input) returns byte[ ]
Isolated Function

Returns the SHA-256 hash of the given data.

1 string dataString = "Hello Ballerina";
2 byte[] data = dataString.toBytes();
3 byte[] hash = crypto:hashSha256(data);

Parameters

  • input byte[ ]
  • Value to be hashed

Return Type

(byte[ ])

Hashed output

hashSha384

function hashSha384(byte[ ] input) returns byte[ ]
Isolated Function

Returns the SHA-384 hash of the given data.

1 string dataString = "Hello Ballerina";
2 byte[] data = dataString.toBytes();
3 byte[] hash = crypto:hashSha384(data);

Parameters

  • input byte[ ]
  • Value to be hashed

Return Type

(byte[ ])

Hashed output

hashSha512

function hashSha512(byte[ ] input) returns byte[ ]
Isolated Function

Returns the SHA-512 hash of the given data.

1 string dataString = "Hello Ballerina";
2 byte[] data = dataString.toBytes();
3 byte[] hash = crypto:hashSha512(data);

Parameters

  • input byte[ ]
  • Value to be hashed

Return Type

(byte[ ])

Hashed output

hmacMd5

function hmacMd5(byte[ ] input, byte[ ] key) returns byte[ ] | Error
Isolated Function

Returns the HMAC using the MD-5 hash function of the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string keyString = "some-secret";
4 byte[] key = keyString.toBytes();
5 byte[] hmac = crypto:hmacMd5(data, key);

Parameters

  • input byte[ ]
  • Value to be hashed

  • key byte[ ]
  • Key used for HMAC generation

Return Type

(byte[ ] | Error)

HMAC output or crypto:Error

hmacSha1

function hmacSha1(byte[ ] input, byte[ ] key) returns byte[ ] | Error
Isolated Function

Returns the HMAC using the SHA-1 hash function of the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string keyString = "some-secret";
4 byte[] key = keyString.toBytes();
5 byte[] hmac = crypto:hmacSha1(data, key);

Parameters

  • input byte[ ]
  • Value to be hashed

  • key byte[ ]
  • Key used for HMAC generation

Return Type

(byte[ ] | Error)

HMAC output or crypto:Error

hmacSha256

function hmacSha256(byte[ ] input, byte[ ] key) returns byte[ ] | Error
Isolated Function

Returns the HMAC using the SHA-256 hash function of the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string keyString = "some-secret";
4 byte[] key = keyString.toBytes();
5 byte[] hmac = crypto:hmacSha256(data, key);

Parameters

  • input byte[ ]
  • Value to be hashed

  • key byte[ ]
  • Key used for HMAC generation

Return Type

(byte[ ] | Error)

HMAC output or crypto:Error

hmacSha384

function hmacSha384(byte[ ] input, byte[ ] key) returns byte[ ] | Error
Isolated Function

Returns the HMAC using the SHA-384 hash function of the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string keyString = "some-secret";
4 byte[] key = keyString.toBytes();
5 byte[] hmac = crypto:hmacSha384(data, key);

Parameters

  • input byte[ ]
  • Value to be hashed

  • key byte[ ]
  • Key used for HMAC generation

Return Type

(byte[ ] | Error)

HMAC output or crypto:Error

hmacSha512

function hmacSha512(byte[ ] input, byte[ ] key) returns byte[ ] | Error
Isolated Function

Returns the HMAC using the SHA-512 hash function of the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 string keyString = "some-secret";
4 byte[] key = keyString.toBytes();
5 byte[] hmac = crypto:hmacSha512(data, key);

Parameters

  • input byte[ ]
  • Value to be hashed

  • key byte[ ]
  • Key used for HMAC generation

Return Type

(byte[ ] | Error)

HMAC output or crypto:Error

signRsaMd5

function signRsaMd5(byte[ ] input, PrivateKey privateKey) returns byte[ ] | Error
Isolated Function

Returns the RSA-MD5-based signature value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[]|crypto:Error signature = crypto:signRsaMd5(data, privateKey);

Parameters

  • input byte[ ]
  • The content to be signed

  • privateKey PrivateKey
  • Private key used for signing

Return Type

(byte[ ] | Error)

The generated signature or else a crypto:Error if the private key is invalid

signRsaSha1

function signRsaSha1(byte[ ] input, PrivateKey privateKey) returns byte[ ] | Error
Isolated Function

Returns the RSA-SHA1-based signature value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[]|crypto:Error signature = crypto:signRsaSha1(data, privateKey);

Parameters

  • input byte[ ]
  • The content to be signed

  • privateKey PrivateKey
  • Private key used for signing

Return Type

(byte[ ] | Error)

The generated signature or else a crypto:Error if the private key is invalid

signRsaSha256

function signRsaSha256(byte[ ] input, PrivateKey privateKey) returns byte[ ] | Error
Isolated Function

Returns the RSA-SHA256-based signature value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[]|crypto:Error signature = crypto:signRsaSha256(data, privateKey);

Parameters

  • input byte[ ]
  • The content to be signed

  • privateKey PrivateKey
  • Private key used for signing

Return Type

(byte[ ] | Error)

The generated signature or else a crypto:Error if the private key is invalid

signRsaSha384

function signRsaSha384(byte[ ] input, PrivateKey privateKey) returns byte[ ] | Error
Isolated Function

Returns the RSA-SHA384-based signature value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[]|crypto:Error signature = crypto:signRsaSha384(data, privateKey);

Parameters

  • input byte[ ]
  • The content to be signed

  • privateKey PrivateKey
  • Private key used for signing

Return Type

(byte[ ] | Error)

The generated signature or else a crypto:Error if the private key is invalid

signRsaSha512

function signRsaSha512(byte[ ] input, PrivateKey privateKey) returns byte[ ] | Error
Isolated Function

Returns the RSA-SHA512-based signature value for the given data.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[]|crypto:Error signature = crypto:signRsaSha512(data, privateKey);

Parameters

  • input byte[ ]
  • The content to be signed

  • privateKey PrivateKey
  • Private key used for signing

Return Type

(byte[ ] | Error)

The generated signature or else a crypto:Error if the private key is invalid

verifyRsaMd5Signature

function verifyRsaMd5Signature(byte[ ] data, byte[ ] signature, PublicKey publicKey) returns boolean | Error
Isolated Function

Verifies the RSA-MD5-based signature.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword")
8 byte[] signature = check crypto:signRsaMd5(data, privateKey);
9 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
10 boolean|crypto:Error validity = crypto:verifyRsaMd5Signature(data, signature, publicKey);

Parameters

  • data byte[ ]
  • The content to be verified

  • signature byte[ ]
  • Signature value

  • publicKey PublicKey
  • Public key used for verification

Return Type

(boolean | Error)

Validity of the signature or else a crypto:Error if the public key is invalid

verifyRsaSha1Signature

function verifyRsaSha1Signature(byte[ ] data, byte[ ] signature, PublicKey publicKey) returns boolean | Error
Isolated Function

Verifies the RSA-SHA1-based signature.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[] signature = check crypto:signRsaMd5(data, privateKey);
9 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
10 boolean|crypto:Error validity = crypto:verifyRsaSha1Signature(data, signature, publicKey);

Parameters

  • data byte[ ]
  • The content to be verified

  • signature byte[ ]
  • Signature value

  • publicKey PublicKey
  • Public key used for verification

Return Type

(boolean | Error)

Validity of the signature or else a crypto:Error if the public key is invalid

verifyRsaSha256Signature

function verifyRsaSha256Signature(byte[ ] data, byte[ ] signature, PublicKey publicKey) returns boolean | Error
Isolated Function

Verifies the RSA-SHA256-based signature.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[] signature = check crypto:signRsaMd5(data, privateKey);
9 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
10 boolean|crypto:Error validity = crypto:verifyRsaSha256Signature(data, signature, publicKey);

Parameters

  • data byte[ ]
  • The content to be verified

  • signature byte[ ]
  • Signature value

  • publicKey PublicKey
  • Public key used for verification

Return Type

(boolean | Error)

Validity of the signature or else a crypto:Error if the public key is invalid

verifyRsaSha384Signature

function verifyRsaSha384Signature(byte[ ] data, byte[ ] signature, PublicKey publicKey) returns boolean | Error
Isolated Function

Verifies the RSA-SHA384-based signature.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[] signature = check crypto:signRsaMd5(data, privateKey);
9 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
10 boolean|crypto:Error validity = crypto:verifyRsaSha384Signature(data, signature, publicKey);

Parameters

  • data byte[ ]
  • The content to be verified

  • signature byte[ ]
  • Signature value

  • publicKey PublicKey
  • Public key used for verification

Return Type

(boolean | Error)

Validity of the signature or else a crypto:Error if the public key is invalid

verifyRsaSha512Signature

function verifyRsaSha512Signature(byte[ ] data, byte[ ] signature, PublicKey publicKey) returns boolean | Error
Isolated Function

Verifies the RSA-SHA512-based signature.

1 string stringData = "Hello Ballerina";
2 byte[] data = stringData.toBytes();
3 crypto:KeyStore keyStore = {
4 path: "/home/ballerina/keystore.p12",
5 password: "keystorePassword"
6 };
7 crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore, "keyAlias", "keyPassword");
8 byte[] signature = check crypto:signRsaMd5(data, privateKey);
9 crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore, "keyAlias");
10 boolean|crypto:Error validity = crypto:verifyRsaSha512Signature(data, signature, publicKey);

Parameters

  • data byte[ ]
  • The content to be verified

  • signature byte[ ]
  • Signature value

  • publicKey PublicKey
  • Public key used for verification

Return Type

(boolean | Error)

Validity of the signature or else a crypto:Error if the public key is invalid