Reputation: 26012
I need to encrypt/decrypt data in the pl/sql with RSA (public/private key) but could not found any way to do it. Already checked dbms_crypto package but it seems it doesn't support RSA algorithm.
Is there any way to use RSA in the PL SQL? Or which asymmetric algorithm would you suggest to use instead?
Problem description
In my case, I generate random keys (few millions in each iteration) which needs to be stored encrypted in DB. Then, when requested I need to decrypt those keys and export as a file. Also, it is not allowed to store duplicate keys in DB. RSA seems perfect for this case but it is not supported in the free version of Oracle cryptography package. Need suggestion to handle those requirements.
Upvotes: 1
Views: 6889
Reputation: 664
My open source Oracle PL/SQL program crypto4ora can encrypt and decrypt messages using RSA public and private keys.
See the project page for installation details. The steps are basically download, run loadjava
, and then run a SQL script.
Below is a full example of generating keys, encrypting, and decrypting:
--Generate keys. Store the private and public key for later.
SELECT CRYPTO.RSA_GENERATE_KEYS(KEY_SIZE => 1024)
FROM DUAL;
--Encrypt and store encrypted text.
SELECT CRYPTO.RSA_ENCRYPT(PLAIN_TEXT => 'This is my secret message.',
PUBLIC_KEY => '<use public key from above>')
FROM DUAL;
--Decrypt, using the encrypted text and the private key, and it returns the plain text.
SELECT CRYPTO.RSA_DECRYPT(ENCRYPTED_TEXT => '<use output from above>',
PRIVATE_KEY => '<use private key from first step>')
FROM DUAL;
Upvotes: 2