If you know the public key (asymmetric key), you can use the function ENCRYPTBYASYMKEY(ASYMKEY_ID('{KEY_NAME}', [Column_Name]) to encrypt data.
How to use asymmetric encryption when only public key is known
I would like to use a blockchain public address to encrypt data inside a SQL table column.
I wonder how to use the asymmetric encryption when I only know the public key of the reciever?
Developer technologies Transact-SQL
3 answers
Sort by: Most helpful
-
-
Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
2020-12-19T10:37:42.523+00:00 You can import a public key with CREATE ASYMMETRIC KEY FROM FILE. This reduces the problem how get the public key to a file which SQL Server can read. Which itself may be trivial - or something which is very difficult to overcome, depending on the situation. It would have been nice if you could create key from a binary string, but that option is only available for certificates.
I should add that the topic for CREATE ASYMMETRIC KEY in Books Online says Specifies the source from which to load the asymmetric key pair, but it works with a public key only. I tested.
-
EchoLiu-MSFT 14,621 Reputation points
2020-12-21T07:12:07.23+00:00 Hi @Arnoud Commandeur ,
Other experts have provided some methods, please also refer to the following article:
Using Asymmetric Encryption and Digital Signatures in a SQL Server 2005 DatabaseRegards
Echo
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues November--What can I do if my transaction log is full?
Hot issues November--How to convert Profiler trace into a SQL Server table