Eastrall / EntityFrameworkCore.DataEncryption

A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.
MIT License
326 stars 54 forks source link

is there any way to open encrypted data with SQL command? #57

Open frtlec opened 11 months ago

frtlec commented 11 months ago

encryption data:e/nPxzHfbQLJrL+JjUvM5A==


  this._encryptionKey = Convert.FromBase64String("xtlG3ujQ70glBQ4jYu7q2g==");
      this._encryptionIV = Convert.FromBase64String("OFHWnm08YigWgT6keFFY0g==");
      _provider = new AesProvider(this._encryptionKey, this._encryptionIV);

I tried many methods, I thought I could open it in SQL because AES is a standard structure, but I couldn't. Can you send a sample code block?

DATABASE:MSSQL

Brawns commented 11 months ago

I encountered the same issue as you did. I am using a MySQL database, and I also want to decrypt data using SQL, but I have been trying for a long time without success.

cargt3 commented 7 months ago

@frtlec @Brawns mysql 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;`

uppercuut commented 4 months ago

@frtlec @Brawns mysql 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;`

do you have any resources to use sql server