What is minimum length of column to save AES_ENCRYPT data?

~ 0 min
2020-04-23 05:36

After using AES_ENCRYPT function, the data is encrypted and enlarged. If the length of column was not enough to save data, the system got ERROR (8072): data encrypt or decrypt fail. The length of encrypted data is the multiple of 16. Therefore, the minimal length of column is (int)(data length / 16 + 1) * 16. For example, if one data length is 28, the encrypted data length is (int)(28 / 16 + 1) * 16 = 32.

 

Here is an example for using AES_ENCRYPT function. We create table t1 and t2, the length of t1.c2 and t2.c2 is 16 and 15. We add one data which length is 15 into t1 and t2 separately. Because t2.c2 was not enough to save encrypted data, system got ERROR (8072).

 

dmSQL> create table t1(c1 int, c2 varchar(16));

dmSQL> create table t2(c1 int, c2 varchar(15));

 

dmSQL> create function libcrypt.aes_encrypt(varchar(32), string) returns varchar(32);

dmSQL> create function libcrypt.aes_decrypt(varchar(32), string) returns varchar(32);

 

dmSQL> insert into t1 values(1, aes_encrypt('123456789012345', 'abc'));

dmSQL> insert into t2 values(2, aes_encrypt('123456789012345', 'abc'));

dmSQL> select c1, aes_decrypt(c2, 'abc') from t1;

 

  C1    AES_DECRYPT(C2, 'ABC')    

===== ===========================

     2 123456789012345

 

dmSQL> select c1, aes_decrypt(c2, 'abc') from t2;

 

  C1    AES_DECRYPT(C2, 'ABCDEF')    

===== ===========================

ERROR (8072): [DBMaker] data encrypt or decrypt fail

 

Version: 5.4.3

Product: Normal/Bundle

Platform: Windows/Linux

Average rating 0 (0 Votes)

You cannot comment on this entry

Tags