public class CryptoHelper extends HelperBase
HelperBase.DATA_TYPE
_actor, _currentObj
Constructor and Description |
---|
CryptoHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror currentObj)
Constructor for CryptoHelper.
|
Modifier and Type | Method and Description |
---|---|
int |
getHashLength(java.lang.String hashAlgorithm)
Return the hash length for the given hash algorithm.
|
int |
getMacLength(java.lang.String macAlgorithm)
Return the MAC (Message Authentication Code) length for the given MAC algorithm.
|
java.lang.Object |
hash(java.lang.Object input,
java.lang.String hashAlgorithm)
Hash the input with a given hash algorithm and return the hashed result.
|
java.lang.Object |
hmac(java.lang.Object input,
java.lang.Object key,
java.lang.String hmacAlgorithm)
Calculate HMAC (key-Hashed Message Authentication Code) for the given input and key.
|
java.security.PrivateKey |
loadPrivateKey(java.lang.String filePath)
Load and return a private key from a RSA private key file in DER format.
|
java.security.PublicKey |
loadPublicKey(java.lang.String filePath)
Load and return a public key from a X.509 certificate file in PEM format.
|
java.lang.Object |
privateDecrypt(java.lang.Object input,
java.security.PrivateKey privateKey,
java.lang.String cipherAlgorithm)
Decrypt the input with an asymmetric cipher private key and return the decrypted result.
|
java.lang.Object |
publicEncrypt(java.lang.Object input,
java.security.PublicKey publicKey,
java.lang.String cipherAlgorithm)
Encrypt the input with an asymmetric cipher public key and return the encrypted result.
|
java.lang.Object |
randomBytes(int size)
Return an array of randomly generated bytes.
|
java.lang.Object |
signWithPrivateKey(java.lang.Object input,
java.security.PrivateKey privateKey,
java.lang.String signAlgorithm)
Sign the given input data with a private key and return the signature.
|
java.lang.Object |
symmetricDecrypt(java.lang.Object input,
java.lang.Object key,
java.lang.String cipherAlgorithm)
Decrypt the input with a symmetric cipher and return the decrypted result.
|
java.lang.Object |
symmetricEncrypt(java.lang.Object input,
java.lang.Object key,
java.lang.String cipherAlgorithm)
Encrypt the input with a symmetric cipher and return the encrypted result.
|
boolean |
verifySignature(java.lang.Object data,
java.lang.Object signature,
java.security.PublicKey publicKey,
java.lang.String signAlgorithm)
Verify the signature for given input data and public key of the signer.
|
_appendNumericToBuffer, _appendToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
public CryptoHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror currentObj)
actor
- The actor associated with this helper.currentObj
- The JavaScript object that this is helping.public int getHashLength(java.lang.String hashAlgorithm) throws IllegalActionException
hashAlgorithm
- The name of the hash algorithm.IllegalActionException
- If the specified hash algorithm is not available.public int getMacLength(java.lang.String macAlgorithm) throws IllegalActionException
macAlgorithm
- The name of the MAC algorithm.IllegalActionException
public java.lang.Object hash(java.lang.Object input, java.lang.String hashAlgorithm) throws IllegalActionException
input
- The input in the JavaScript object to be hashed.hashAlgorithm
- The name of the hash algorithm to be used. (Examples: MD5, SHA-1, SHA-256)IllegalActionException
- If the specified hash algorithm is not available.public java.lang.Object hmac(java.lang.Object input, java.lang.Object key, java.lang.String hmacAlgorithm) throws IllegalActionException
input
- The input in the JavaScript object to be HMAC hashed.key
- The key to be used for HMAC calculation.hmacAlgorithm
- The name of the HMAC algorithm.IllegalActionException
- If the HMAC calculation fails.public java.security.PrivateKey loadPrivateKey(java.lang.String filePath) throws IllegalActionException
filePath
- The path for the file that stores a RSA private key in DER format.IllegalActionException
- If there is a problem with loading the private key.public java.security.PublicKey loadPublicKey(java.lang.String filePath) throws IllegalActionException
filePath
- The path for the file that stores a X.509 certificate.IllegalActionException
- If there is a problem with loading the public key.public java.lang.Object privateDecrypt(java.lang.Object input, java.security.PrivateKey privateKey, java.lang.String cipherAlgorithm) throws IllegalActionException
input
- The cipher text to be decrypted.privateKey
- The private key of the destination entity.cipherAlgorithm
- The name of the asymmetric cipher to be used for decryption.IllegalActionException
- If the private key decryption fails.public java.lang.Object publicEncrypt(java.lang.Object input, java.security.PublicKey publicKey, java.lang.String cipherAlgorithm) throws IllegalActionException
input
- The clear text message to be encrypted.publicKey
- The public key of the entity that will decrypt the message.cipherAlgorithm
- The name of the asymmetric cipher to be used for encryption.IllegalActionException
- If the public key encryption fails.public java.lang.Object randomBytes(int size) throws IllegalActionException
size
- The number of bytes to be generated.IllegalActionException
- If the generated bytes cannot be converted to JavaScript array.public java.lang.Object signWithPrivateKey(java.lang.Object input, java.security.PrivateKey privateKey, java.lang.String signAlgorithm) throws IllegalActionException
input
- The input data to be signed in a JavaScript object.privateKey
- The public key of the entity that will decrypt the message.signAlgorithm
- The name of the algorithm to be used for signing.IllegalActionException
public java.lang.Object symmetricDecrypt(java.lang.Object input, java.lang.Object key, java.lang.String cipherAlgorithm) throws IllegalActionException
input
- The cipher text to be decrypted.key
- The secret key for the cipher.cipherAlgorithm
- The name of the symmetric cipher algorithm to be used for decryption. (examples: AES-128-CBC, DES-ECB)IllegalActionException
- If the decryption fails.public java.lang.Object symmetricEncrypt(java.lang.Object input, java.lang.Object key, java.lang.String cipherAlgorithm) throws IllegalActionException
input
- The clear text message to be encrypted.key
- The secret key for the cipher.cipherAlgorithm
- The name of the symmetric cipher algorithm to be used for encryption. (examples: AES-128-CBC, DES-ECB)IllegalActionException
- If the encryption fails.public boolean verifySignature(java.lang.Object data, java.lang.Object signature, java.security.PublicKey publicKey, java.lang.String signAlgorithm) throws java.lang.IllegalArgumentException
data
- The input data to be verified.signature
- The signature to be verified.publicKey
- The public key to be used for signature verification.signAlgorithm
- The name of the algorithm to be used for signature verification.java.lang.IllegalArgumentException