2021年3月23日星期二

Encrypt and Decrypt column between Postgres SQL and SQL Server

Is it possible to encrypt a column in Postgres SQL and decrypt in SQL Server?

In Postgres SQL I used PGP_SYM_ENCRYPT to encrypt data and stored in a table.

CREATE TABLE encrypt_test( id integer, custname character varying(255), custname_encrypt character varying(255));    INSERT INTO encrypt_test VALUES(1, 'AAA' ,PGP_SYM_ENCRYPT('AAA','P@ssw0rd'));  

This data is transfered to SQL server through ETL. And now I need to decrypt the encrypted column from SQL server.

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'P@ssw0rd';  CREATE CERTIFICATE Certificate_test WITH SUBJECT = 'Test Encryption';  CREATE SYMMETRIC KEY EncryptTest WITH ALGORITHM = AES_128 ENCRYPTION BY CERTIFICATE Certificate_test;      OPEN SYMMETRIC KEY EncryptTest DECRYPTION BY CERTIFICATE Certificate_test;    SELECT CONVERT(varchar(max), DecryptByKey(CUSTNAME_ENCRYPT)) AS Decrypted_test FROM ods.ENCRYPT_TEST;    CLOSE SYMMETRIC KEY EncryptTest;    

But it doesn't work. It returns null. Can someone helps me with solution?

https://stackoverflow.com/questions/66774946/encrypt-and-decrypt-column-between-postgres-sql-and-sql-server March 24, 2021 at 12:51PM

没有评论:

发表评论