8.6.5 MySQL Enterprise Encryption Component Function Descriptions (original) (raw)

8.6.5 MySQL Enterprise Encryption Component Function Descriptions

MySQL Enterprise Encryption functions have these general characteristics:

The component functions only support the RSA encryption algorithm.

For additional examples and discussion, seeSection 8.6.3, “MySQL Enterprise Encryption Usage and Examples”.

-- Generate private/public key pair  
SET @priv = create_asymmetric_priv_key('RSA', 2048);  
SET @pub = create_asymmetric_pub_key('RSA', @priv);  
-- Encrypt using public key, decrypt using private key  
SET @ciphertext = asymmetric_encrypt('RSA', 'The quick brown fox', @pub);  
SET @plaintext = asymmetric_decrypt('RSA', @ciphertext, @priv);  

Suppose that:

SET @s = a string to be encrypted  
SET @priv = a valid private RSA key string in PEM format  
SET @pub = the corresponding public RSA key string in PEM format  

Then these identity relationships hold:

asymmetric_decrypt('RSA', asymmetric_encrypt('RSA', @s, @pub), @priv) = @s  
-- Set the encryption algorithm and digest type  
SET @algo = 'RSA';  
SET @dig_type = 'SHA512';  
-- Create private/public key pair  
SET @priv = create_asymmetric_priv_key(@algo, 2048);  
SET @pub = create_asymmetric_pub_key(@algo, @priv);  
-- Generate digest from string  
SET @dig = create_digest(@dig_type, 'The quick brown fox');  
-- Generate signature for digest and verify signature against digest  
SET @sig = asymmetric_sign(@algo, @dig, @priv, @dig_type);  
SET @verf = asymmetric_verify(@algo, @dig, @sig, @pub, @dig_type);  
SET @priv = create_asymmetric_priv_key('RSA', 2048);  
SET @pub = create_asymmetric_pub_key('RSA', @priv);  
SET @dig = create_digest('SHA512', 'The quick brown fox');