klyn.cryptography.Cipher.rsaDecrypt
method
public static rsaDecrypt(cipherText as String, privateKeyPem as String, padding as String = "OAEP", hashAlgorithm as String = "SHA-256", inputEncoding as String = "base64") as String throws CryptoException:
Description

Decrypts RSA ciphertext with a private key.

Parameters
ParameterDescription
cipherTextEncoded ciphertext.
privateKeyPemPEM-encoded private key.
paddingRSA encryption padding. Defaults to OAEP.
hashAlgorithmHash used by OAEP when applicable.
inputEncodingCiphertext encoding: base64, base64url or hex.
Returns

Decrypted UTF-8 text.

Throws
  • CryptoException when decryption fails.
Example
import klyn.cryptography

keys = RSAKeyPairGenerator().generateKeyPair()
encrypted = Cipher.rsaEncrypt("hello", keys.publicKeyPem)
print(Cipher.rsaDecrypt(encrypted, keys.privateKeyPem))