klyn.cryptography.Cipher.rsaEncrypt
method
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:
Description
Encrypts text with an RSA public key. Supported paddings: - `OAEP` (recommended, default) - `PKCS1` For `OAEP`, `hashAlgorithm` controls both the OAEP digest and MGF1 digest.
import klyn.cryptography

keys = RSAKeyPairGenerator().generateKeyPair()
encrypted = Cipher.rsaEncrypt("hello", keys.publicKeyPem)
print(encrypted)
Parameters
  • 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`.
Returns
Encoded ciphertext.
Throws
  • CryptoException when encryption fails. ```klyn import klyn.cryptography keys = RSAKeyPairGenerator().generateKeyPair() encrypted = Cipher.rsaEncrypt("hello", keys.publicKeyPem) print(encrypted) ```