EntityFrameworkCore.DataEncryption icon indicating copy to clipboard operation
EntityFrameworkCore.DataEncryption copied to clipboard

Has anyone written a stored procedure in the database management tool that can query the decrypted data?

Open Brawns opened this issue 1 year ago • 4 comments

Brawns avatar Jun 12 '23 10:06 Brawns

done with clr

planeteleven0 avatar Jul 05 '23 03:07 planeteleven0

Want to directly query the decrypted data in the database management tool

Brawns avatar Jul 08 '23 06:07 Brawns

yes , create a .net framework library project , with same algorithm , use that dll as clr by creating the functions

planeteleven0 avatar Jul 08 '23 18:07 planeteleven0

my sql script

`SET @keyBase = 'xxx'; SET @encrypted_data = 'xxx';

SET @@SESSION.block_encryption_mode = 'aes-256-cbc';

-- Convert the keyBase to binary SET @keyBaseBinary = CONVERT(@keyBase USING utf8);

-- Convert the binary keyBase to Base64 SET @key = TO_BASE64(@keyBaseBinary);

-- Decode the keyBase from Base64 encoding SET @binary_encrypted_data = FROM_BASE64(@encrypted_data);

-- Extract the first 16 bytes from the decoded data as the IV SET @iv = SUBSTRING(@binary_encrypted_data, 1, 16);

-- Remove the IV from the binary data SET @data_without_iv = SUBSTRING(@binary_encrypted_data, 17);

-- Decrypt the data using AES_DECRYPT in MySQL SELECT CAST(AES_DECRYPT(@data_without_iv, @key, @iv) AS CHAR) AS decrypted_data;`

cargt3 avatar Nov 20 '23 17:11 cargt3