Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
frtlec opened this issue Jul 18, 2023 · 3 comments
Open

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

frtlec opened this issue Jul 18, 2023 · 3 comments

Comments

@frtlec
Copy link

frtlec commented Jul 18, 2023

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
Copy link

Brawns commented Jul 31, 2023

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
Copy link

cargt3 commented Nov 20, 2023

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

@IbrahimMNada
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants