Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ECDH256 : IDisposable
- {
- internal readonly ECDiffieHellmanCng ecdh;
- public byte[] PublicKey { get; }
- public ECDH256()
- {
- ecdh = new ECDiffieHellmanCng
- {
- KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash,
- HashAlgorithm = CngAlgorithm.Sha256
- };
- PublicKey = ecdh.PublicKey.ToByteArray();
- }
- public void Dispose() => ecdh.Dispose();
- }
- public static class ECDH256Extensions
- {
- public static byte[] DeriveSharedKey(this ECDH256 ECDH, byte[] PublicKey)
- {
- byte[] SharedKey
- = ECDH.ecdh.DeriveKeyMaterial(ECDiffieHellmanCngPublicKey.FromByteArray(PublicKey, CngKeyBlobFormat.EccPublicBlob));
- ECDH.Dispose();
- return SharedKey;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement