- Documentation
- Reference manual
- Packages
- SWI-Prolog SSL Interface
- library(crypto): Cryptography and authentication library
- SWI-Prolog SSL Interface
3.7 Asymmetric encryption and decryption
The following predicates provide asymmetric RSA encryption and decryption. This means that the key that is used for encryption is different from the one used to decrypt the data:
- [det]rsa_private_decrypt(+PrivateKey, +CipherText, -PlainText, +Options)
- [det]rsa_private_encrypt(+PrivateKey, +PlainText, -CipherText, +Options)
- [det]rsa_public_decrypt(+PublicKey, +CipherText, -PlainText, +Options)
- [det]rsa_public_encrypt(+PublicKey, +PlainText, -CipherText, +Options)
- RSA Public key encryption and decryption primitives. A string can be
safely communicated by first encrypting it and have the peer decrypt it
with the matching key and predicate. The length of the string is limited
by the key length.
Options:
- encoding(+Encoding)
- Encoding to use for Data. Default is
utf8
. Alternatives areutf8
andoctet
. - padding(+PaddingScheme)
- Padding scheme to use. Default is
pkcs1
. Alternatives arepkcs1_oaep
,sslv23
andnone
. Note thatnone
should only be used if you implement cryptographically sound padding modes in your application code as encrypting unpadded data with RSA is insecure
- Errors
ssl_error(Code, LibName, FuncName, Reason)
is raised if there is an error, e.g., if the text is too long for the key.- See also
- load_private_key/3, load_public_key/2 can be use to load keys from a file. The predicate load_certificate/2 can be used to obtain the public key from a certificate.