Encryption & Decryption

The following Ruby encryption examples use the OpenSSL cryptography toolkit.

Encrypt Message

Encrypt message using RSA public key with PKCS1-OAEP padding:

require 'openssl'
    def encrypt_RSA(key, message='my plaintext string')
    key.public_encrypt(message, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
end

Decrypt Package

Decrypt a package using RSA private key with PKCS1-OAEP padding:

require 'openssl'
    def decrypt_RSA(key, package)
    key.private_decrypt(package, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
end

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×