Cipher
class in package klyn.cryptography

    public class Cipher:

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:

- AES encryption/decryption in `GCM`, `CBC` and `CTR`
- RSA encryption/decryption in `OAEP` and `PKCS1`

    import klyn.cryptography

    keyGenerator = AESKeyGenerator()
    keyGenerator.initialize(256)
    key = keyGenerator.generateKey()
    payload = Cipher.aesGcmEncrypt("secret", key)
    plain = Cipher.aesGcmDecrypt(payload, key)
    print(plain)

Methods

Modifier and Type | Member | Description
--- | --- | ---
public static | aesCbcDecrypt `aesCbcDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64") as String throws CryptoException:` | Convenience AES-CBC decryption helper.
public static | aesCbcEncrypt `aesCbcEncrypt(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 | aesCtrDecrypt `aesCtrDecrypt(payload as AESCipherText, key as String, keyEncoding as String = "base64") as String throws CryptoException:` | Convenience AES-CTR decryption helper.
public static | aesCtrEncrypt `aesCtrEncrypt(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 | aesDecrypt `aesDecrypt(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 | aesEncrypt `aesEncrypt(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 | aesGcmDecrypt `aesGcmDecrypt(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 | aesGcmEncrypt `aesGcmEncrypt(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 `rsaDecrypt(cipherText as String, privateKeyPem as String, padding as String = "OAEP", hashAlgorithm as String = "SHA-256", inputEncoding as String = "base64") as String throws CryptoException:` | Decrypts RSA ciphertext with a private key.
public static | rsaEncrypt `rsaEncrypt(plainText as String, publicKeyPem as String, padding as String = "OAEP", hashAlgorithm as String = "SHA-256", outputEncoding as String = "base64") as String throws CryptoException:` | Encrypts text with an RSA public key.