gogoru
gogoru

Reputation: 386

mysql function for Encrypt/Decrypt like java

how can I simulate this code in mysql:

Encrypt

TextEncryptor encryptor = Encryptors.text(key, salt);
encryptor.encrypt(message);

Decrypt

TextEncryptor decryptor = Encryptors.text(key, salt);
decryptor.decrypt(message);

I need decrypt the data from the db that I encrytp in java code.

Upvotes: 0

Views: 229

Answers (2)

PyThon
PyThon

Reputation: 1067

Use AES_ENCRYPT / AES_DECRYPT

INSERT INTO t VALUES (1, AES_ENCRYPT('text',UNHEX('F3229A0B371ED2D9441B830D21A390C3')));

https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_aes-encrypt

Upvotes: 1

Shadow
Shadow

Reputation: 34232

Mysql offers a range of encryption functions, out of which only aes_encrypt() has not been deprecated yet.

However, if you want to encrypt data stored in databases, you may consider applying encryption on an operating system or database product level, so your data is encrypted, but you can still use sql to filter your data without much inconvenience.

Upvotes: 0

Related Questions