Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public ecPublicKey(jwkPublicKey jwkFormatKey)
 {
     this.X = Base64Url.from(jwkFormatKey.x);
     this.Y = Base64Url.from(jwkFormatKey.y);
 }
Ejemplo n.º 3
0
 public ecPrivateKey(jwkPrivateKey jwkFormatKey)
 {
     this.D = Base64Url.from(jwkFormatKey.d);
 }
Ejemplo n.º 4
0
 public rsaPublicKey(jwkPublicKey jwkFormatKey)
 {
     this.Modulus  = Base64Url.from(jwkFormatKey.n);
     this.Exponent = Base64Url.from(jwkFormatKey.e);
 }
Ejemplo n.º 5
0
 public jwkPrivateKey(camelot.ECKeyPair ecKeyPair, string curveName)
     : base(ecKeyPair, curveName)
 {
     this.d = Base64Url.to(ecKeyPair.ExportPrivateKey());
 }