public static 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.
Supported paddings:
OAEP (recommended, default)PKCS1For OAEP, hashAlgorithm controls both the OAEP digest and MGF1 digest.
| Parameter | Description |
|---|---|
plainText | Source text interpreted as UTF-8. |
publicKeyPem | PEM-encoded public key. |
padding | RSA encryption padding. Defaults to OAEP. |
hashAlgorithm | Hash used by OAEP when applicable. |
outputEncoding | Output encoding: base64, base64url or hex. |
Encoded ciphertext.
import klyn.cryptography
keys = RSAKeyPairGenerator().generateKeyPair()
encrypted = Cipher.rsaEncrypt("hello", keys.publicKeyPem)
print(encrypted)