6.6.4 MySQL Enterprise Encryption Function Descriptions (original) (raw)

6.6.4 MySQL Enterprise Encryption Function Descriptions

MySQL Enterprise Encryption functions have these general characteristics:

Several of the functions take an encryption algorithm argument. The following table summarizes the supported algorithms by function.

Table 6.37 Supported Algorithms by Function

Note

Although you can create keys using any of the RSA, DSA, or DH encryption algorithms, other functions that take key arguments might accept only certain types of keys. For example,asymmetric_encrypt() andasymmetric_decrypt() accept only RSA keys.

The following descriptions describe the calling sequences for MySQL Enterprise Encryption functions. For additional examples and discussion, seeSection 6.6.2, “MySQL Enterprise Encryption Usage and Examples”.

SET @dhp = create_dh_parameters(1024);  
SET @priv1 = create_asymmetric_priv_key('DH', @dhp);  
SET @pub1 = create_asymmetric_pub_key('DH', @priv1);  
SET @priv2 = create_asymmetric_priv_key('DH', @dhp);  
SET @pub2 = create_asymmetric_pub_key('DH', @priv2);  

Suppose further that you use the private key from one pair and the public key from the other pair to create a symmetric key string. Then this symmetric key identity relationship holds:

asymmetric_derive(@pub1, @priv2) = asymmetric_derive(@pub2, @priv1)  
-- Generate private/public key pair  
SET @priv = create_asymmetric_priv_key('RSA', 1024);  
SET @pub = create_asymmetric_pub_key('RSA', @priv);  
-- Encrypt using private key, decrypt using public key  
SET @ciphertext = asymmetric_encrypt('RSA', 'The quick brown fox', @priv);  
SET @plaintext = asymmetric_decrypt('RSA', @ciphertext, @pub);  
-- 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, @priv), @pub) = @s  
asymmetric_decrypt('RSA', asymmetric_encrypt('RSA', @s, @pub), @priv) = @s  
-- Set the encryption algorithm and digest type  
SET @algo = 'RSA';  
SET @dig_type = 'SHA224';  
-- Create private/public key pair  
SET @priv = create_asymmetric_priv_key(@algo, 1024);  
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('DSA', 2048);  
SET @pub = create_asymmetric_pub_key('DSA', @priv);  

For an example showing DH key generation, see the description of asymmetric_derive().
Some general considerations in choosing key lengths and encryption algorithms:

SET @dhp = create_dh_parameters(1024);  
SET @dig = create_digest('SHA512', The quick brown fox');  

The resulting digest string is suitable for use withasymmetric_sign() andasymmetric_verify().