SoftFluent/EntityFrameworkCore.DataEncryption

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

Opened this issue · 4 comments

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

done with clr

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

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

cargt3 commented

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;`