public class Cipher:
High-level encryption facade.
This class is intentionally focused on encryption and decryption. Hashing, MACs, signatures, random generation and key derivation are exposed by dedicated classes such as MessageDigest, Mac, Signature, SecureRandom, KeyGenerator, KeyPairGenerator and SecretKeyFactory.
Supported features:
GCM, CBC and CTROAEP and PKCS1import klyn.cryptography
keyGenerator = AESKeyGenerator()
keyGenerator.initialize(256)
key = keyGenerator.generateKey()
payload = Cipher.aesGcmEncrypt("secret", key)
plain = Cipher.aesGcmDecrypt(payload, key)
print(plain)| Modifier and Type | Member | Description |
|---|---|---|
| public static | aesCbcDecryptaesCbcDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64") as String throws CryptoException: |
Convenience AES-CBC decryption helper. |
| public static | aesCbcEncryptaesCbcEncrypt(plainText as String, key as String, keyEncoding as String = "base64", iv as String = null, ivEncoding as String = "base64") as AESCipherText throws CryptoException: |
Convenience AES-CBC encryption helper. |
| public static | aesCtrDecryptaesCtrDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64") as String throws CryptoException: |
Convenience AES-CTR decryption helper. |
| public static | aesCtrEncryptaesCtrEncrypt(plainText as String, key as String, keyEncoding as String = "base64", iv as String = null, ivEncoding as String = "base64") as AESCipherText throws CryptoException: |
Convenience AES-CTR encryption helper. |
| public static | aesDecryptaesDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64", aad as String = null) as String throws CryptoException: |
Decrypts an AES payload produced by `aesEncrypt`. |
| public static | aesEncryptaesEncrypt(plainText as String, key as String, mode as String = "GCM", keyEncoding as String = "base64", iv as String = null, ivEncoding as String = "base64", aad as String = null) as AESCipherText throws CryptoException: |
Encrypts text with AES. |
| public static | aesGcmDecryptaesGcmDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64", aad as String = null) as String throws CryptoException: |
Convenience AES-GCM decryption helper. |
| public static | aesGcmEncryptaesGcmEncrypt(plainText as String, key as String, keyEncoding as String = "base64", iv as String = null, ivEncoding as String = "base64", aad as String = null) as AESCipherText throws CryptoException: |
Convenience AES-GCM encryption helper. |
| public static | rsaDecrypt | Decrypts RSA ciphertext with a private key. |
| public static | rsaEncrypt | Encrypts text with an RSA public key. |