private static Track2Sdk.JsonWebKey CreateTrack2SdkJWK(RSA rsa, WebKeyConverterExtraInfo extraInfo = null)
 {
     if (rsa == null)
     {
         throw new ArgumentNullException("rsa");
     }
     RSAParameters rsaParameters = rsa.ExportParameters(true);
     var           webKey        = new Track2Sdk.JsonWebKey(rsa, default, extraInfo?.KeyOps?.Select(op => new Track2Sdk.KeyOperation(op)))
 public Track2Sdk.JsonWebKey ConvertToTrack2SdkKeyFromFile(FileInfo fileInfo, SecureString password, WebKeyConverterExtraInfo extraInfo = null)
 {
     if (CanProcess(fileInfo))
     {
         return(ConvertToTrack2SdkJsonWebKey(fileInfo.FullName, extraInfo));
     }
     else if (next != null)
     {
         return(next.ConvertToTrack2SdkKeyFromFile(fileInfo, password, extraInfo));
     }
     else
     {
         throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedFileFormat, fileInfo.Name));
     }
 }
        public Track1Sdk.JsonWebKey ConvertKeyFromFile(FileInfo fileInfo, SecureString password, WebKeyConverterExtraInfo extraInfo = null)
        {
            if (CanProcess(fileInfo))
            {
                var jwk = Convert(fileInfo.FullName);

                if (JwkHelper.IsEC(extraInfo?.KeyType))
                {
                    jwk.Kty       = JsonWebKeyType.EllipticCurveHsm; // byok -> hsm
                    jwk.CurveName = extraInfo.CurveName;
                }

                return(jwk);
            }
            else if (next != null)
            {
                return(next.ConvertKeyFromFile(fileInfo, password, extraInfo));
            }
            else
            {
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedFileFormat, fileInfo.Name));
            }
        }
        private Track2Sdk.JsonWebKey ConvertToTrack2SdkJsonWebKey(string byokFileName, WebKeyConverterExtraInfo extraInfo = null)
        {
            byte[] byokBlob = File.ReadAllBytes(byokFileName);

            if (byokBlob == null || byokBlob.Length == 0)
            {
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.InvalidKeyBlob, "BYOK"));
            }

            return(new Track2Sdk.JsonWebKey(new RSACryptoServiceProvider(), default, extraInfo?.KeyOps?.Select(op => new Track2Sdk.KeyOperation(op)))
        private Track2Sdk.JsonWebKey ConvertToTrack2SdkJsonWebKey(string pfxFileName, SecureString pfxPassword, WebKeyConverterExtraInfo extraInfo = null)
        {
            X509Certificate2 certificate = new X509Certificate2(pfxFileName, pfxPassword, X509KeyStorageFlags.Exportable);

            if (!certificate.HasPrivateKey)
            {
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.InvalidKeyBlob, "pfx"));
            }

            var rsaKey = certificate.PrivateKey as RSA;

            if (rsaKey != null)
            {
                return(CreateTrack2SdkJWK(rsaKey, extraInfo));
            }

            var ecKey = certificate.PrivateKey as ECDsa;

            if (ecKey != null)
            {
                return(CreateTrack2SdkJWK(ecKey, extraInfo));
            }

            // to do: support converting oct to jsonwebKey

            throw new ArgumentException(string.Format(KeyVaultProperties.Resources.ImportNotSupported, "oct-HSM"));
        }