ballerina/crypto module
Module overview
This module provides the necessary utilities that are required to hash content using different hashing mechanisms and algorithms.
Samples
Hashing
The sample given below shows how to use hashing functions such as hashSha512
to calculate the hash value of a byte array and then encode the byte array using a common encoding algorithm.
import ballerina/crypto;
import ballerina/encoding;
import ballerina/io;
public function main() {
// Input value for crypto operations.
string input = "Hello Ballerina";
byte[] inputArr = input.toByteArray("UTF-8");
// Hashing input value using different hashing algorithms, and printing hash value using Hex encoding.
byte[] output = crypto:hashMd5(inputArr);
io:println("Hash with MD5: " + encoding:encodeHex(output));
output = crypto:hashSha1(inputArr);
io:println("Hash with SHA1: " + encoding:encodeHex(output));
output = crypto:hashSha256(inputArr);
io:println("Hash with SHA256: " + encoding:encodeHex(output));
output = crypto:hashSha384(inputArr);
io:println("Hash with SHA384: " + encoding:encodeHex(output));
output = crypto:hashSha512(inputArr);
io:println("Hash with SHA512: " + encoding:encodeHex(output));
}
HMAC Generation
The sample given below shows how to use HMAC functions such as hmacSha512
to calculate the HMAC value of a byte array and then encode the byte array using a common encoding algorithm.
import ballerina/crypto;
import ballerina/encoding;
import ballerina/io;
public function main() {
string charEncoding = "UTF-8";
// Input value for crypto operations.
string input = "Hello Ballerina";
byte[] inputArr = input.toByteArray(charEncoding);
// The key used for HMAC generation.
string key = "somesecret";
byte[] keyArr = key.toByteArray(charEncoding);
// HMAC generation for input value using different HMAC algorithms, and printing HMAC value using Hex encoding.
byte[] output = crypto:hmacMd5(inputArr, keyArr);
io:println("HMAC with MD5: " + encoding:encodeHex(output));
output = crypto:hmacSha1(inputArr, keyArr);
io:println("HMAC with SHA1: " + encoding:encodeHex(output));
output = crypto:hmacSha256(inputArr, keyArr);
io:println("HMAC with SHA256: " + encoding:encodeHex(output));
output = crypto:hmacSha384(inputArr, keyArr);
io:println("HMAC with SHA384: " + encoding:encodeHex(output));
output = crypto:hmacSha512(inputArr, keyArr);
io:println("HMAC with SHA512: " + encoding:encodeHex(output));
}
Calculating CRC32B Checksum
The sample given below shows how to use crc32b
function to calculate the CRC32B checksum.
import ballerina/crypto;
import ballerina/io;
public function main() {
// Input value for cryto operations.
string input = "Hello Ballerina";
// Hex encoded CRC32B checksum generation for input value.
io:println("CRC32B for text: " + crypto:crc32b(input));
// The XML content to be hashed.
xml xmlContent = xml `<foo>Hello Ballerina</foo>`;
io:println("CRC32 for xml content: " + crypto:crc32b(xmlContent));
}
Signing
The sample given below shows how to use signing functions such as signRsaSha512
to get the signature value of a byte array and then encode the byte array using a common encoding algorithm.
import ballerina/crypto;
import ballerina/encoding;
import ballerina/io;
public function main() returns error? {
// Input value for cryto operations.
string input = "Hello Ballerina";
byte[] inputArr = input.toByteArray("UTF-8");
// PrivateKey used for signing operations.
crypto:KeyStore keyStore = { path: "/home/ballerina/keystore.p12", password: "ballerina" };
crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore = keyStore, keyAlias = "ballerina",
keyPassword = "ballerina");
// Signing input value using different signature algorithms, and printing the signature value
// using Hex encoding.
byte[] output = check crypto:signRsaMd5(inputArr, privateKey);
io:println("RSA-MD5 signature: " + encoding:encodeHex(output));
output = check crypto:signRsaSha1(inputArr, privateKey);
io:println("RSA-SHA1 signature: " + encoding:encodeHex(output));
output = check crypto:signRsaSha256(inputArr, privateKey);
io:println("RSA-SHA256 signature: " + encoding:encodeHex(output));
output = check crypto:signRsaSha384(inputArr, privateKey);
io:println("RSA-SHA384 signature: " + encoding:encodeHex(output));
output = check crypto:signRsaSha512(inputArr, privateKey);
io:println("RSA-SHA512 signature: " + encoding:encodeHex(output));
}
RSA Encryption
The sample given below shows how to use encryption function encryptRsaEcb
and decryption function decryptRsaEcb
to perform RSA encryption and decryption.
import ballerina/crypto;
import ballerina/encoding;
import ballerina/io;
public function main() returns error? {
// Input value for cryto operations.
string input = "Hello Ballerina";
byte[] inputArr = input.toByteArray("UTF-8");
crypto:KeyStore keyStore = { path: "/home/ballerina/keystore.p12", password: "ballerina" };
// Public key used for encryption.
crypto:PublicKey publicKey = check crypto:decodePublicKey(keyStore = keyStore, keyAlias = "ballerina");
// Private key used for decryption.
crypto:PrivateKey privateKey = check crypto:decodePrivateKey(keyStore = keyStore, keyAlias = "ballerina",
keyPassword = "ballerina");
// Encrypt and decrypt input value using RSA ECB PKCS1 padding.
byte[] output = check crypto:encryptRsaEcb(inputArr, publicKey);
output = check crypto:decryptRsaEcb(output, privateKey);
io:println("RSA ECB PKCS1 decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using RSA ECB OAEPwithSHA512andMGF1 padding.
output = check crypto:encryptRsaEcb(inputArr, publicKey, padding = crypto:OAEPwithSHA512andMGF1);
output = check crypto:decryptRsaEcb(output, privateKey, padding = crypto:OAEPwithSHA512andMGF1);
io:println("RSA ECB OAEPwithSHA512andMGF1 decrypted value: " + encoding:byteArrayToString(output));
}
AES Encryption
The sample given below shows how to use encryption function encryptAesCbc
and decryption function decryptAesCbc
to perform AES encryption and decryption.
import ballerina/crypto;
import ballerina/encoding;
import ballerina/io;
import ballerina/math;
public function main() returns error? {
// Input value for cryto operations.
string input = "Hello Ballerina!";
byte[] inputArr = input.toByteArray("UTF-8");
// Randomly generate a 128 bit key.
byte[16] keyArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
foreach var i in 0...15 {
keyArr[i] = check byte.convert(math:randomInRange(0, 255));
}
// Randomly generate a 128 bit IV.
byte[16] ivArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
foreach var i in 0...15 {
ivArr[i] = check byte.convert(math:randomInRange(0, 255));
}
// Encrypt and decrypt input value using AES CBC PKCS5 padding.
byte[] output = check crypto:encryptAesCbc(inputArr, keyArr, ivArr);
output = check crypto:decryptAesCbc(output, keyArr, ivArr);
io:println("AES CBC PKCS5 decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using AES CBC no padding.
output = check crypto:encryptAesCbc(inputArr, keyArr, ivArr, padding = crypto:NONE);
output = check crypto:decryptAesCbc(output, keyArr, ivArr, padding = crypto:NONE);
io:println("AES CBC no padding decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using AES GCM PKCS5 padding.
output = check crypto:encryptAesGcm(inputArr, keyArr, ivArr);
output = check crypto:decryptAesGcm(output, keyArr, ivArr);
io:println("AES GCM PKCS5 decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using AES GCM no padding.
output = check crypto:encryptAesGcm(inputArr, keyArr, ivArr, padding = crypto:NONE);
output = check crypto:decryptAesGcm(output, keyArr, ivArr, padding = crypto:NONE);
io:println("AES GCM no padding decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using AES ECB PKCS5 padding.
output = check crypto:encryptAesEcb(inputArr, keyArr);
output = check crypto:decryptAesEcb(output, keyArr);
io:println("AES ECB PKCS5 decrypted value: " + encoding:byteArrayToString(output));
// Encrypt and decrypt input value using AES ECB no padding.
output = check crypto:encryptAesEcb(inputArr, keyArr, padding = crypto:NONE);
output = check crypto:decryptAesEcb(output, keyArr, padding = crypto:NONE);
io:println("AES ECB no padding decrypted value: " + encoding:byteArrayToString(output));
}
Type Definitions
Type | Values | Description | |
---|---|---|---|
AesPadding | PKCS5 | NONE | Padding algorithms supported with AES encryption and decryption |
|
KeyAlgorithm | RSA | The key algorithms supported by crypto module. |
|
RsaPadding | PKCS1 | OAEPwithSHA512andMGF1 | OAEPwithSHA384andMGF1 | OAEPwithMD5andMGF1 | OAEPWithSHA256AndMGF1 | OAEPWithSHA1AndMGF1 | Padding algorithms supported with RSA encryption and decryption |
Records Summary
Record | Description | ||
---|---|---|---|
Certificate | X509 public key certificate information. | ||
CryptoError | Error relevant to crypto operations. | ||
KeyStore | Record for providing key store related configurations. | ||
PrivateKey | Private key used in cryptographic operations. | ||
PublicKey | Public key used in cryptographic operations. | ||
TrustStore | Record for providing trust store related configurations. |
Functions Summary
Return Type | Function and Description | ||
---|---|---|---|
string | crc32b(any input) Returns Hex encoded CRC32B value for the provided element. This accepts |
||
PrivateKey|error<> | decodePrivateKey(crypto:KeyStore? keyStore, string? keyAlias, string? keyPassword) Read a private key from the provided PKCS#12 archive file. |
||
PublicKey|error<> | decodePublicKey(crypto:KeyStore? keyStore, string? keyAlias) Read a public key from the provided PKCS#12 archive file. |
||
byte[]|error<> | decryptAesCbc(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding) Returns AES CBC decrypted value for the given AES CBC encrypted data. |
||
byte[]|error<> | decryptAesEcb(byte[] input, byte[] key, NONE|PKCS5 padding) Returns AES ECB decrypted value for the given AES ECB encrypted data. |
||
byte[]|error<> | decryptAesGcm(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding, int? tagSize) Returns AES GCM decrypted value for the given AES GCM encrypted data. |
||
byte[]|error<> | decryptRsaEcb(byte[] input, crypto:PrivateKey|crypto:PublicKey key, PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 padding) Returns RSA decrypted value for the given RSA encrypted data. |
||
byte[]|error<> | encryptAesCbc(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding) Returns AES CBC encrypted value for the given data. |
||
byte[]|error<> | encryptAesEcb(byte[] input, byte[] key, NONE|PKCS5 padding) Returns AES ECB encrypted value for the given data. |
||
byte[]|error<> | encryptAesGcm(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding, int? tagSize) Returns AES GCM encrypted value for the given data. |
||
byte[]|error<> | encryptRsaEcb(byte[] input, crypto:PrivateKey|crypto:PublicKey key, PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 padding) Returns RSA encrypted value for the given data. |
||
byte[] | hashMd5(byte[] input) Returns the MD5 hash of the given data. |
||
byte[] | hashSha1(byte[] input) Returns the SHA-1 hash of the given data. |
||
byte[] | hashSha256(byte[] input) Returns the SHA-256 hash of the given data. |
||
byte[] | hashSha384(byte[] input) Returns the SHA-384 hash of the given data. |
||
byte[] | hashSha512(byte[] input) Returns the SHA-512 hash of the given data. |
||
byte[] | hmacMd5(byte[] input, byte[] key) Returns the HMAC using MD-5 hash function of the given data. |
||
byte[] | hmacSha1(byte[] input, byte[] key) Returns the HMAC using SHA-1 hash function of the given data. |
||
byte[] | hmacSha256(byte[] input, byte[] key) Returns the HMAC using SHA-256 hash function of the given data. |
||
byte[] | hmacSha384(byte[] input, byte[] key) Returns the HMAC using SHA-384 hash function of the given data. |
||
byte[] | hmacSha512(byte[] input, byte[] key) Returns the HMAC using SHA-512 hash function of the given data. |
||
byte[]|error<> | signRsaMd5(byte[] input, crypto:PrivateKey privateKey) Returns RSA-MD5 based signature value for the given data. |
||
byte[]|error<> | signRsaSha1(byte[] input, crypto:PrivateKey privateKey) Returns RSA-SHA1 based signature value for the given data. |
||
byte[]|error<> | signRsaSha256(byte[] input, crypto:PrivateKey privateKey) Returns RSA-SHA256 based signature value for the given data. |
||
byte[]|error<> | signRsaSha384(byte[] input, crypto:PrivateKey privateKey) Returns RSA-SHA384 based signature value for the given data. |
||
byte[]|error<> | signRsaSha512(byte[] input, crypto:PrivateKey privateKey) Returns RSA-SHA512 based signature value for the given data. |
||
boolean|error<> | verifyRsaMd5Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) Verify RSA-MD5 based signature. |
||
boolean|error<> | verifyRsaSha1Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) Verify RSA-SHA1 based signature. |
||
boolean|error<> | verifyRsaSha256Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) Verify RSA-SHA256 based signature. |
||
boolean|error<> | verifyRsaSha384Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) Verify RSA-SHA384 based signature. |
||
boolean|error<> | verifyRsaSha512Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) Verify RSA-SHA512 based signature. |
Constants
public type Certificate record
X509 public key certificate information.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
version0 | int | Version number |
|
serial | int | Serial number |
|
issuer | string | Issuer name |
|
subject | string | Subject name |
|
notBefore | time:Time | Not before validity period of certificate |
|
notAfter | time:Time | Not after validity period of certificate |
|
signature | byte[] | Raw signature bits |
|
signingAlgorithm | string | Signature algorithm |
public type CryptoError record
Error relevant to crypto operations.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
message | string | Error message |
public type KeyStore record
Record for providing key store related configurations.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
path | string | Path to the key store file |
|
password | string | Key store password |
public type PrivateKey record
Private key used in cryptographic operations.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
algorithm | RSA | Key algorithm |
public type PublicKey record
Public key used in cryptographic operations.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
algorithm | RSA | Key algorithm |
|
certificate | crypto:Certificate? | Public key certificate |
public type TrustStore record
Record for providing trust store related configurations.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
path | string | Path to the key store file |
|
password | string | Key store password |
public function crc32b(any input) returns (string)
Returns Hex encoded CRC32B value for the provided element. This accepts string
, byte[]
, json
and xml
content.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | any | Value for checksum generation |
Return Type | Description | ||
---|---|---|---|
string | The generated checksum |
public function decodePrivateKey(crypto:KeyStore? keyStore, string? keyAlias, string? keyPassword) returns (PrivateKey|error<>)
Read a private key from the provided PKCS#12 archive file.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
keyStore | crypto:KeyStore? | () | Key store configuration |
keyAlias | string? | () | Key alias |
keyPassword | string? | () | Key password |
Return Type | Description | ||
---|---|---|---|
PrivateKey|error<> | Reference to the private key or error if private key was unreadable |
public function decodePublicKey(crypto:KeyStore? keyStore, string? keyAlias) returns (PublicKey|error<>)
Read a public key from the provided PKCS#12 archive file.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
keyStore | crypto:KeyStore? | () | Key store configuration |
keyAlias | string? | () | Key alias |
Return Type | Description | ||
---|---|---|---|
PublicKey|error<> | Reference to the public key or error if private key was unreadable |
public function decryptAesCbc(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding) returns (byte[]|error<>)
Returns AES CBC decrypted value for the given AES CBC encrypted data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be decrypted |
|
key | byte[] | Encryption key |
|
iv | byte[] | Initialization vector |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Decrypted data or error if key is invalid |
public function decryptAesEcb(byte[] input, byte[] key, NONE|PKCS5 padding) returns (byte[]|error<>)
Returns AES ECB decrypted value for the given AES ECB encrypted data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be decrypted |
|
key | byte[] | Encryption key |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Decrypted data or error if key is invalid |
public function decryptAesGcm(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding, int? tagSize) returns (byte[]|error<>)
Returns AES GCM decrypted value for the given AES GCM encrypted data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be decrypted |
|
key | byte[] | Encryption key |
|
iv | byte[] | Initialization vector |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
tagSize | int? | 128 | Tag size |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Decrypted data or error if key is invalid |
public function decryptRsaEcb(byte[] input, crypto:PrivateKey|crypto:PublicKey key, PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 padding) returns (byte[]|error<>)
Returns RSA decrypted value for the given RSA encrypted data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be decrypted |
|
key | crypto:PrivateKey|crypto:PublicKey | Private or public key used for encryption |
|
padding | PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 | PKCS1 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Decrypted data or error if key is invalid |
public function encryptAesCbc(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding) returns (byte[]|error<>)
Returns AES CBC encrypted value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be encrypted |
|
key | byte[] | Encryption key |
|
iv | byte[] | Initialization vector |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Encrypted data or error if key is invalid |
public function encryptAesEcb(byte[] input, byte[] key, NONE|PKCS5 padding) returns (byte[]|error<>)
Returns AES ECB encrypted value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be encrypted |
|
key | byte[] | Encryption key |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Encrypted data or error if key is invalid |
public function encryptAesGcm(byte[] input, byte[] key, byte[] iv, NONE|PKCS5 padding, int? tagSize) returns (byte[]|error<>)
Returns AES GCM encrypted value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be encrypted |
|
key | byte[] | Encryption key |
|
iv | byte[] | Initialization vector |
|
padding | NONE|PKCS5 | PKCS5 | The padding |
tagSize | int? | 128 | Tag size |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Encrypted data or error if key is invalid |
public function encryptRsaEcb(byte[] input, crypto:PrivateKey|crypto:PublicKey key, PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 padding) returns (byte[]|error<>)
Returns RSA encrypted value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be encrypted |
|
key | crypto:PrivateKey|crypto:PublicKey | Private or public key used for encryption |
|
padding | PKCS1|OAEPwithMD5andMGF1|OAEPWithSHA1AndMGF1|OAEPWithSHA256AndMGF1|OAEPwithSHA384andMGF1|OAEPwithSHA512andMGF1 | PKCS1 | The padding |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | Encrypted data or error if key is invalid |
public function hashMd5(byte[] input) returns (byte[])
Returns the MD5 hash of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
Return Type | Description | ||
---|---|---|---|
byte[] | Hashed output |
public function hashSha1(byte[] input) returns (byte[])
Returns the SHA-1 hash of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
Return Type | Description | ||
---|---|---|---|
byte[] | Hashed output |
public function hashSha256(byte[] input) returns (byte[])
Returns the SHA-256 hash of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
Return Type | Description | ||
---|---|---|---|
byte[] | Hashed output |
public function hashSha384(byte[] input) returns (byte[])
Returns the SHA-384 hash of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
Return Type | Description | ||
---|---|---|---|
byte[] | Hashed output |
public function hashSha512(byte[] input) returns (byte[])
Returns the SHA-512 hash of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
Return Type | Description | ||
---|---|---|---|
byte[] | Hashed output |
public function hmacMd5(byte[] input, byte[] key) returns (byte[])
Returns the HMAC using MD-5 hash function of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
|
key | byte[] | Key used for HMAC generation |
Return Type | Description | ||
---|---|---|---|
byte[] | HMAC output |
public function hmacSha1(byte[] input, byte[] key) returns (byte[])
Returns the HMAC using SHA-1 hash function of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
|
key | byte[] | Key used for HMAC generation |
Return Type | Description | ||
---|---|---|---|
byte[] | HMAC output |
public function hmacSha256(byte[] input, byte[] key) returns (byte[])
Returns the HMAC using SHA-256 hash function of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
|
key | byte[] | Key used for HMAC generation |
Return Type | Description | ||
---|---|---|---|
byte[] | HMAC output |
public function hmacSha384(byte[] input, byte[] key) returns (byte[])
Returns the HMAC using SHA-384 hash function of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
|
key | byte[] | Key used for HMAC generation |
Return Type | Description | ||
---|---|---|---|
byte[] | HMAC output |
public function hmacSha512(byte[] input, byte[] key) returns (byte[])
Returns the HMAC using SHA-512 hash function of the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | Value to be hashed |
|
key | byte[] | Key used for HMAC generation |
Return Type | Description | ||
---|---|---|---|
byte[] | HMAC output |
public function signRsaMd5(byte[] input, crypto:PrivateKey privateKey) returns (byte[]|error<>)
Returns RSA-MD5 based signature value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be signed |
|
privateKey | crypto:PrivateKey | Private key used for signing |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | The generated signature or error if private key is invalid |
public function signRsaSha1(byte[] input, crypto:PrivateKey privateKey) returns (byte[]|error<>)
Returns RSA-SHA1 based signature value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be signed |
|
privateKey | crypto:PrivateKey | Private key used for signing |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | The generated signature or error if private key is invalid |
public function signRsaSha256(byte[] input, crypto:PrivateKey privateKey) returns (byte[]|error<>)
Returns RSA-SHA256 based signature value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be signed |
|
privateKey | crypto:PrivateKey | Private key used for signing |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | The generated signature or error if private key is invalid |
public function signRsaSha384(byte[] input, crypto:PrivateKey privateKey) returns (byte[]|error<>)
Returns RSA-SHA384 based signature value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be signed |
|
privateKey | crypto:PrivateKey | Private key used for signing. |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | The generated signature or error if private key is invalid |
public function signRsaSha512(byte[] input, crypto:PrivateKey privateKey) returns (byte[]|error<>)
Returns RSA-SHA512 based signature value for the given data.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
input | byte[] | The content to be signed |
|
privateKey | crypto:PrivateKey | Private key used for signing |
Return Type | Description | ||
---|---|---|---|
byte[]|error<> | The generated signature or error if private key is invalid |
public function verifyRsaMd5Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) returns (boolean|error<>)
Verify RSA-MD5 based signature.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
data | byte[] | The content to be verified |
|
signature | byte[] | Signature value |
|
publicKey | crypto:PublicKey | Public key used for verification |
Return Type | Description | ||
---|---|---|---|
boolean|error<> | Validity of the signature or error if public key is invalid |
public function verifyRsaSha1Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) returns (boolean|error<>)
Verify RSA-SHA1 based signature.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
data | byte[] | The content to be verified |
|
signature | byte[] | Signature value |
|
publicKey | crypto:PublicKey | Public key used for verification |
Return Type | Description | ||
---|---|---|---|
boolean|error<> | Validity of the signature or error if public key is invalid |
public function verifyRsaSha256Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) returns (boolean|error<>)
Verify RSA-SHA256 based signature.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
data | byte[] | The content to be verified |
|
signature | byte[] | Signature value |
|
publicKey | crypto:PublicKey | Public key used for verification |
Return Type | Description | ||
---|---|---|---|
boolean|error<> | Validity of the signature or error if public key is invalid |
public function verifyRsaSha384Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) returns (boolean|error<>)
Verify RSA-SHA384 based signature.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
data | byte[] | The content to be verified |
|
signature | byte[] | Signature value |
|
publicKey | crypto:PublicKey | Public key used for verification |
Return Type | Description | ||
---|---|---|---|
boolean|error<> | Validity of the signature or error if public key is invalid |
public function verifyRsaSha512Signature(byte[] data, byte[] signature, crypto:PublicKey publicKey) returns (boolean|error<>)
Verify RSA-SHA512 based signature.
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
data | byte[] | The content to be verified |
|
signature | byte[] | Signature value |
|
publicKey | crypto:PublicKey | Public key used for verification |
Return Type | Description | ||
---|---|---|---|
boolean|error<> | Validity of the signature or error if public key is invalid |