Exemplo n.º 1
0
 public rsaPrivateKey(jwkPrivateKey jwkFormatKey)
 {
     this.Modulus  = Base64Url.from(jwkFormatKey.n);
     this.Exponent = Base64Url.from(jwkFormatKey.e);
     this.D        = Base64Url.from(jwkFormatKey.d);
     this.P        = Base64Url.from(jwkFormatKey.p);
     this.Q        = Base64Url.from(jwkFormatKey.q);
     this.DP       = Base64Url.from(jwkFormatKey.dp);
     this.DQ       = Base64Url.from(jwkFormatKey.dq);
     this.InverseQ = Base64Url.from(jwkFormatKey.qi);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public ecPublicKey(jwkPublicKey jwkFormatKey)
 {
     this.X = Base64Url.from(jwkFormatKey.x);
     this.Y = Base64Url.from(jwkFormatKey.y);
 }
Exemplo n.º 4
0
 public ecPrivateKey(jwkPrivateKey jwkFormatKey)
 {
     this.D = Base64Url.from(jwkFormatKey.d);
 }
Exemplo n.º 5
0
 public rsaPublicKey(jwkPublicKey jwkFormatKey)
 {
     this.Modulus  = Base64Url.from(jwkFormatKey.n);
     this.Exponent = Base64Url.from(jwkFormatKey.e);
 }