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:
DescriptionEncrypts 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)
ReturnsEncoded ciphertext.