public CngKey toPublicCngKey() { // BCRYPT_ECDH_PRIVATE_P256_MAGIC 0x324B4345 // BCRYPT_ECDH_PRIVATE_P384_MAGIC 0x344B4345 byte[] magic, keyLen; if (crv.ToLower() == "p-256") { // BCRYPT_ECDH_PUBLIC_P256_MAGIC 0x314B4345 magic = new byte[] { 0x45, 0x43, 0x4B, 0x31 }; keyLen = new byte[] { 32, 0, 0, 0 }; } else if (crv.ToLower() == "p-384") { // BCRYPT_ECDH_PUBLIC_P384_MAGIC 0x334B4345 magic = new byte[] { 0x45, 0x43, 0x4B, 0x33 }; keyLen = new byte[] { 48, 0, 0, 0 }; } else { throw new InvalidOperationException("Unsupported curve"); } byte[] xbytes = Base64Url.from(this.x); byte[] ybytes = Base64Url.from(this.y); byte[] blob = new byte[xbytes.Length + ybytes.Length + magic.Length + 4]; magic.CopyTo(blob, 0); keyLen.CopyTo(blob, 4); xbytes.CopyTo(blob, 8); ybytes.CopyTo(blob, xbytes.Length + 8); CngKey cngKey = CngKey.Import(blob, CngKeyBlobFormat.EccPublicBlob); return(cngKey); }
public ecPublicKey(jwkPublicKey jwkFormatKey) { this.X = Base64Url.from(jwkFormatKey.x); this.Y = Base64Url.from(jwkFormatKey.y); }
public ecPrivateKey(jwkPrivateKey jwkFormatKey) { this.D = Base64Url.from(jwkFormatKey.d); }
public rsaPublicKey(jwkPublicKey jwkFormatKey) { this.Modulus = Base64Url.from(jwkFormatKey.n); this.Exponent = Base64Url.from(jwkFormatKey.e); }
public jwkPrivateKey(camelot.ECKeyPair ecKeyPair, string curveName) : base(ecKeyPair, curveName) { this.d = Base64Url.to(ecKeyPair.ExportPrivateKey()); }