0

I am using System.Security.Cryptography.Cng (4.7.0).

I have exported a public key from a CngKey object using

byte[] publicKey = cngKey.Export(CngKeyBlobFormat.GenericPublicBlob);

How can I use this at a later time to create an RSACng object for public-key encryption?

Mo B.
  • 5,307
  • 3
  • 25
  • 42

1 Answers1

0

A CngKey can be recreated from the blob like this:

using CngKey key = CngKey.Import(blob, CngKeyBlobFormat.GenericPublicBlob);

And then we can create an RSACng for e.g. encrypting data:

using RSACng rsaCng = new RSACng(key);
Mo B.
  • 5,307
  • 3
  • 25
  • 42