How to use asymmetric encryption when only public key is known

Arnoud Commandeur 1 Reputation point
2020-12-18T14:34:43.037+00:00

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
{count} votes

3 answers

Sort by: Most helpful
  1. Guoxiong 8,206 Reputation points
    2020-12-18T23:56:02.713+00:00

    If you know the public key (asymmetric key), you can use the function ENCRYPTBYASYMKEY(ASYMKEY_ID('{KEY_NAME}', [Column_Name]) to encrypt data.


  2. 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.


  3. 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 Database

    Regards
    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.