示例#1
0
        public jwkPublicKey(CngKey cngKey)
        {
            switch (cngKey.Algorithm.Algorithm)
            {
            case "ECDH_P256":
                this.crv = "P-256";
                break;

            case "ECDH_P384":
                this.crv = "P-384";
                break;

            default:
                throw new InvalidOperationException("Unsupported curve");
            }

            this.kty         = "EC";
            this.extractable = true;

            byte[] keyBlob = cngKey.Export(CngKeyBlobFormat.EccPublicBlob);

            // bytes 0-3 curve type; byte 4-7 key length; x bytes; y bytes
            var keyLen = keyBlob[4];

            byte[] xbytes = new byte[keyLen];
            byte[] ybytes = new byte[keyLen];

            Array.Copy(keyBlob, 8, xbytes, 0, keyLen);
            Array.Copy(keyBlob, 8 + xbytes.Length, ybytes, 0, keyLen);

            this.x = Base64Url.to(xbytes);
            this.y = Base64Url.to(ybytes);
        }
示例#2
0
 public jwkPublicKey(RSAParameters rsaKey)
 {
     this.kty         = "RSA";
     this.extractable = true;
     this.n           = Base64Url.to(rsaKey.Modulus);
     this.e           = Base64Url.to(rsaKey.Exponent);
 }
示例#3
0
 public jwkPrivateKey(RSAParameters rsaKey)
     : base(rsaKey)
 {
     this.d  = Base64Url.to(rsaKey.D);
     this.p  = Base64Url.to(rsaKey.P);
     this.q  = Base64Url.to(rsaKey.Q);
     this.dp = Base64Url.to(rsaKey.DP);
     this.dq = Base64Url.to(rsaKey.DQ);
     this.qi = Base64Url.to(rsaKey.InverseQ);
 }
示例#4
0
        public jwkPublicKey(camelot.ECKeyPair ecKeyPair, string curveName)
        {
            EllipticCurvePointFp point =
                SEC1EncodingFp.DecodePoint(ecKeyPair.ExportPublicKey(), ecKeyPair.Curve);

            this.crv         = curveName;
            this.kty         = "EC";
            this.extractable = true;

            byte[] xBytes = point.X.ToByteArrayUnsigned();
            Array.Reverse(xBytes);

            byte[] yBytes = point.Y.ToByteArrayUnsigned();
            Array.Reverse(yBytes);

            this.x = Base64Url.to(xBytes);
            this.y = Base64Url.to(yBytes);
        }
示例#5
0
 public jwkPrivateKey(camelot.ECKeyPair ecKeyPair, string curveName)
     : base(ecKeyPair, curveName)
 {
     this.d = Base64Url.to(ecKeyPair.ExportPrivateKey());
 }