Ejemplo n.º 1
0
        private static Track2Sdk.JsonWebKey CreateTrack2SdkJWK(ECDsa ecdSa)
        {
            if (ecdSa == null)
            {
                throw new ArgumentNullException("ecdSa");
            }

            System.Security.Cryptography.ECParameters ecParameters = ecdSa.ExportParameters(true);
            var webKey = new Track2Sdk.JsonWebKey(ecdSa)
            {
                // note: Keyvault need distinguish EC and EC-HSM
                KeyType   = Track2Sdk.KeyType.EcHsm,
                CurveName = ecParameters.Curve.CurveType.ToString(),
                D         = ecParameters.D,
                X         = ecParameters.Q.X,
                Y         = ecParameters.Q.Y
            };

            return(webKey);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a track 2 JsonWebKey object to track 1 type
        /// </summary>
        /// <param name="track2Key">track 2 key</param>
        /// <returns>equivalent track 1 key</returns>
        public static Track1Sdk.JsonWebKey ToTrack1JsonWebKey(this Track2Sdk.JsonWebKey track2Key)
        {
            Track1Sdk.JsonWebKey track1Key;

            // convert key specific properties
            if (track2Key.KeyType == Track2Sdk.KeyType.Ec || track2Key.KeyType == Track2Sdk.KeyType.EcHsm)
            {
                track1Key = new Track1Sdk.JsonWebKey(new Track1Sdk.ECParameters()
                {
                    Curve = track2Key.CurveName.ToString(),
                    X     = track2Key.X,
                    Y     = track2Key.Y,
                    D     = track2Key.D
                });
            }
            else if (track2Key.KeyType == Track2Sdk.KeyType.Rsa || track2Key.KeyType == Track2Sdk.KeyType.RsaHsm)
            {
                track1Key = new Track1Sdk.JsonWebKey(track2Key.ToRSA());
            }
            // SDK doesn't have a definition of OctHSM, so I need to use string comparison
            else if (track2Key.KeyType == Track2Sdk.KeyType.Oct || track2Key.KeyType.ToString() == @"oct-HSM")
            {
                track1Key     = new Track1Sdk.JsonWebKey();
                track1Key.Kty = track2Key.KeyType.ToString();
            }
            else
            {
                throw new Exception("Not supported");
            }

            // metadata
            track1Key.KeyOps = new List <string>();
            foreach (var op in track2Key.KeyOps)
            {
                track1Key.KeyOps.Add(op.ToString());
            }
            track1Key.Kid = track2Key.Id;

            return(track1Key);
        }
Ejemplo n.º 3
0
        private static Track2Sdk.JsonWebKey CreateTrack2SdkJWK(RSA rsa)
        {
            if (rsa == null)
            {
                throw new ArgumentNullException("rsa");
            }
            RSAParameters rsaParameters = rsa.ExportParameters(true);
            var           webKey        = new Track2Sdk.JsonWebKey(rsa)
            {
                // note: Keyvault need distinguish RSA and RSA-HSM
                KeyType = Track2Sdk.KeyType.RsaHsm,
                N       = rsaParameters.Modulus,
                E       = rsaParameters.Exponent,
                DP      = rsaParameters.DP,
                DQ      = rsaParameters.DQ,
                QI      = rsaParameters.InverseQ,
                Q       = rsaParameters.Q,
                D       = rsaParameters.D,
                P       = rsaParameters.P
            };

            return(webKey);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Keys.KeyVaultKey"/> for mocking purposes.
 /// </summary>
 /// <param name="properties">Sets the <see cref="Keys.KeyVaultKey.Properties"/> property, which provides the <see cref="Keys.KeyVaultKey.Id"/> and <see cref="Keys.KeyVaultKey.Name"/> properties.</param>
 /// <param name="key">Sets the <see cref="Keys.KeyVaultKey.Key"/> property, which provides the <see cref="Keys.KeyVaultKey.KeyType"/> and <see cref="Keys.KeyVaultKey.KeyOperations"/> properties.</param>
 /// <returns>A new instance of the <see cref="Keys.KeyVaultKey"/> for mocking purposes.</returns>
 public static KeyVaultKey KeyVaultKey(KeyProperties properties, JsonWebKey key) => new KeyVaultKey(properties)
 {
     Key = key,
 };
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the KeyImportOptions class.
 /// </summary>
 /// <param name="name">The name of the key.</param>
 /// <param name="keyMaterial">The <see cref="JsonWebKey"/> properties of the key.</param>
 public KeyImportOptions(string name, JsonWebKey keyMaterial)
     : base(name)
 {
     KeyMaterial = keyMaterial;
 }
Ejemplo n.º 6
0
        public virtual async Task <Response <Key> > ImportKeyAsync(string name, JsonWebKey keyMaterial, CancellationToken cancellationToken = default)
        {
            await Task.CompletedTask;

            throw new NotImplementedException();
        }
Ejemplo n.º 7
0
 public virtual Response <Key> ImportKey(string name, JsonWebKey keyMaterial, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public KeyImportOptions(string name, JsonWebKey keyMaterial, bool hsm)
     : base(name)
 {
     KeyMaterial = keyMaterial;
     Hsm         = hsm;
 }
Ejemplo n.º 9
0
 public Key(string name, string keyId, string keyType, IList <string> keyOperations)
     : base(name)
 {
     KeyMaterial = new JsonWebKey(keyId, keyType, keyOperations);
 }