/// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var key = CngKey.Import(keyBlob, GetPlatformKeyBlobType(blobType));
            return new CngCryptographicKey(key);
        }
    public void PublicKeyRoundTrip(AsymmetricAlgorithm algorithm, int keySize, CryptographicPublicKeyBlobType format)
    {
        var keyAlgorithm = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(algorithm);

        using (var key = keyAlgorithm.CreateKeyPair(keySize))
        {
            byte[] keyBlob = key.ExportPublicKey(format);
            using (var key2 = keyAlgorithm.ImportPublicKey(keyBlob, format))
            {
                byte[] key2Blob = key2.ExportPublicKey(format);
                CollectionAssertEx.AreEqual(keyBlob, key2Blob);

                try
                {
                    // We use a non-empty buffer here because monotouch's
                    // Security.SecKey.Encrypt method has a bug that throws
                    // IndexOutOfRangeException when given empty buffers.
                    WinRTCrypto.CryptographicEngine.Encrypt(key2, new byte[1]);
                }
                catch (NotSupportedException)
                {
                    // Some algorithms, such as ECDSA, only support signing/verifying.
                }

                this.logger.WriteLine(Convert.ToBase64String(keyBlob));
            }
        }
    }
Example #3
0
        /// <inheritdoc />
        public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
        {
            byte[]        keyData    = KeyDataWithTag(GetPublicKeyIdentifierWithTag(this.keyIdentifier)).ToArray();
            RSAParameters parameters = KeyFormatter.Pkcs1.Read(keyData);

            return(KeyFormatter.GetFormatter(blobType).Write(parameters));
        }
Example #4
0
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            RSAParameters parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);

            // Inject the PKCS#1 public key into the KeyChain.
            string keyIdentifier       = Guid.NewGuid().ToString();
            string publicKeyIdentifier = RsaCryptographicKey.GetPublicKeyIdentifierWithTag(keyIdentifier);
            var    keyQueryDictionary  = RsaCryptographicKey.CreateKeyQueryDictionary(publicKeyIdentifier);

            keyQueryDictionary[KSec.ValueData]    = NSData.FromArray(KeyFormatter.Pkcs1.Write(parameters, includePrivateKey: false));
            keyQueryDictionary[KSec.AttrKeyClass] = KSec.AttrKeyClassPublic;
            keyQueryDictionary[KSec.ReturnRef]    = NSNumber.FromBoolean(true);
            IntPtr resultHandle;
            int    status = RsaCryptographicKey.SecItemAdd(keyQueryDictionary.Handle, out resultHandle);

            if (resultHandle != IntPtr.Zero)
            {
                var key = new SecKey(resultHandle, true);
                return(new RsaCryptographicKey(key, keyIdentifier, this.Algorithm));
            }
            else
            {
                throw new InvalidOperationException("SecItemAdd return " + status);
            }
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var key = this.platform.ImportPublicKey(keyBlob.ToBuffer(), GetPlatformKeyBlobType(blobType));
            return new CryptographicKey(key);
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var key = CngKey.Import(keyBlob, GetPlatformKeyBlobType(blobType));

            return(new CngCryptographicKey(key, null));
        }
Example #7
0
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var key = this.platform.ImportPublicKey(keyBlob.ToBuffer(), GetPlatformKeyBlobType(blobType));

            return(new CryptographicKey(key));
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var rsa = new Platform.RSACryptoServiceProvider();

            rsa.ImportParameters(KeyFormatter.ToPlatformParameters(KeyFormatter.GetFormatter(blobType).Read(keyBlob)));
            return(new RsaCryptographicKey(rsa, this.algorithm));
        }
Example #9
0
    public void PublicKeyFormat(CryptographicPublicKeyBlobType format)
    {
        var rsa = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaOaepSha1);
        var key = rsa.CreateKeyPair(512);

        byte[] serialized = key.ExportPublicKey(format);
        Assert.NotNull(serialized);
        Assert.NotEmpty(serialized);
    }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var        parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);
            var        spec       = new RSAPublicKeySpec(new BigInteger(1, parameters.Modulus), new BigInteger(1, parameters.Exponent));
            KeyFactory factory    = KeyFactory.GetInstance("RSA");
            IPublicKey publicKey  = factory.GeneratePublic(spec);

            return(new RsaCryptographicKey(publicKey, parameters, this.algorithm));
        }
    public void PublicKeyInterop(AsymmetricAlgorithm asymmetricAlgorithm, CryptographicPublicKeyBlobType blobType, string publicKeyBase64)
    {
        IAsymmetricKeyAlgorithmProvider algorithm;

        algorithm = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(asymmetricAlgorithm);

        var    key      = algorithm.ImportPublicKey(Convert.FromBase64String(publicKeyBase64), blobType);
        string exported = Convert.ToBase64String(key.ExportPublicKey(blobType));

        Assert.Equal(publicKeyBase64, exported);
    }
Example #12
0
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
 {
     try
     {
         return(this.platformKey.ExportPublicKey(blobType.ToPlatformKeyBlobType()).ToArray());
     }
     catch (NotImplementedException ex)
     {
         throw new NotSupportedException(ex.Message, ex);
     }
 }
Example #13
0
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     try
     {
         return(this.key.ExportPublicKey(AsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType)).ToArray());
     }
     catch (NotImplementedException ex)
     {
         throw new NotSupportedException(ex.Message, ex);
     }
 }
        /// <summary>
        /// Gets the platform-specific enum value for the given PCL enum value.
        /// </summary>
        /// <param name="blobType">The platform independent enum value for the blob type.</param>
        /// <returns>The platform-specific enum value for the equivalent blob type.</returns>
        internal static CngKeyBlobFormat GetPlatformKeyBlobType(CryptographicPublicKeyBlobType blobType)
        {
            switch (blobType)
            {
            case CryptographicPublicKeyBlobType.BCryptPublicKey:
                return(CngKeyBlobFormat.GenericPublicBlob);

            default:
                throw new NotSupportedException();
            }
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            using (var provider = NCryptOpenStorageProvider(KeyStorageProviders.MS_KEY_STORAGE_PROVIDER))
            {
                byte[] bcryptPublicBlob = blobType == this.NativePublicKeyFormatEnum
            ? keyBlob
            : KeyFormatter.GetFormatter(this.NativePublicKeyFormatEnum).Write(KeyFormatter.GetFormatter(blobType).Read(keyBlob));
                var key = NCryptImportKey(provider, null, this.NativePublicKeyFormatString, IntPtr.Zero, bcryptPublicBlob);
                return(this.CreateKey(key, isPublicOnly: true));
            }
        }
Example #16
0
 /// <summary>
 /// Gets the formatter to use for a given blob type.
 /// </summary>
 /// <param name="blobType">Type of the key blob.</param>
 /// <returns>An instance of <see cref="KeyFormatter"/></returns>
 internal static KeyFormatter GetFormatter(CryptographicPublicKeyBlobType blobType)
 {
     switch (blobType)
     {
         case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
             return X509SubjectPublicKeyInfo;
         case CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey:
             return Pkcs1PrependZeros;
         case CryptographicPublicKeyBlobType.Capi1PublicKey:
             return Capi;
         default:
             throw new NotSupportedException();
     }
 }
Example #17
0
        public void KeyFormatters_PublicKeyRoundTrip(CryptographicPublicKeyBlobType format)
        {
            var formatter = KeyFormatter.GetFormatter(format);

            byte[] custom            = formatter.Write(rsaParameters.Value, includePrivateKey: false);
            var    rsaParametersRead = formatter.Read(custom);

            Assert.Equal <byte>(rsaParameters.Value.Exponent, rsaParametersRead.Exponent);
            Assert.Equal <byte>(rsaParameters.Value.Modulus, rsaParametersRead.Modulus);

            Assert.Null(rsaParametersRead.D);
            Assert.Null(rsaParametersRead.P);
            Assert.Null(rsaParametersRead.Q);
            Assert.Null(rsaParametersRead.DP);
            Assert.Null(rsaParametersRead.DQ);
            Assert.Null(rsaParametersRead.InverseQ);
        }
Example #18
0
        /// <summary>
        /// Gets the formatter to use for a given blob type.
        /// </summary>
        /// <param name="blobType">Type of the key blob.</param>
        /// <returns>An instance of <see cref="KeyFormatter"/></returns>
        internal static KeyFormatter GetFormatter(CryptographicPublicKeyBlobType blobType)
        {
            switch (blobType)
            {
            case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
                return(X509SubjectPublicKeyInfo);

            case CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey:
                return(Pkcs1PrependZeros);

            case CryptographicPublicKeyBlobType.Capi1PublicKey:
                return(Capi);

            default:
                throw new NotSupportedException();
            }
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType)
        {
            Requires.NotNull(keyBlob, nameof(keyBlob));

            CngKeyBlobFormat format = GetPlatformKeyBlobType(blobType);
            CngKey?          key;

            try
            {
                key = CngKey.Import(keyBlob, format);
            }
            catch (NotImplementedException ex)
            {
                throw new PlatformNotSupportedException($"CngKey.Import(byte[], {format}) threw an exception.", ex);
            }

            return(new CngCryptographicKey(key, null, this.Algorithm));
        }
Example #20
0
    public async Task PerfectForwardSecrecy()
    {
        CryptographicPublicKeyBlobType publicBlobType = CryptographicPublicKeyBlobType.BCryptPublicKey;
        var    cancellationToken = Debugger.IsAttached ? CancellationToken.None : new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token;
        string pipeName          = Guid.NewGuid().ToString();
        var    ecdsaAlgorithm    = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.EcdsaP256Sha256);

        var streams = FullDuplexStream.CreateStreams();

        using (var bob = ecdsaAlgorithm.CreateKeyPair(256))
            using (var alice = ecdsaAlgorithm.CreateKeyPair(256))
            {
                var bobPublic   = ecdsaAlgorithm.ImportPublicKey(bob.ExportPublicKey(publicBlobType), publicBlobType);
                var alicePublic = ecdsaAlgorithm.ImportPublicKey(alice.ExportPublicKey(publicBlobType), publicBlobType);

                Task aliceRole = this.PlayAliceRoleAsync(alice, bobPublic, streams.Item1, cancellationToken);
                Task bobRole   = this.PlayBobRoleAsync(bob, alicePublic, streams.Item2, cancellationToken);
                await Task.WhenAll(aliceRole, bobRole);
            }
    }
Example #21
0
        /// <inheritdoc />
        public override byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
        {
            try
            {
                byte[] nativeBlob    = NCryptExportKey(this.Key, SafeKeyHandle.Null, this.Provider.NativePublicKeyFormatString, IntPtr.Zero).ToArray();
                byte[] formattedBlob = blobType == this.Provider.NativePublicKeyFormatEnum
                    ? nativeBlob
                    : KeyFormatter.GetFormatter(blobType).Write(KeyFormatter.GetFormatter(this.Provider.NativePublicKeyFormatEnum).Read(nativeBlob));
                return(formattedBlob);
            }
            catch (SecurityStatusException ex)
            {
                if (ex.NativeErrorCode == SECURITY_STATUS.NTE_NOT_SUPPORTED)
                {
                    throw new NotSupportedException(ex.Message, ex);
                }

                throw;
            }
        }
Example #22
0
        /// <summary>
        /// Gets the formatter to use for a given blob type.
        /// </summary>
        /// <param name="blobType">Type of the key blob.</param>
        /// <returns>An instance of <see cref="KeyFormatter"/></returns>
        public static KeyFormatter GetFormatter(CryptographicPublicKeyBlobType blobType)
        {
            switch (blobType)
            {
            case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
                return(X509SubjectPublicKeyInfo);

            case CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey:
                return(Pkcs1);

            case CryptographicPublicKeyBlobType.Capi1PublicKey:
                return(Capi);

#if !SILVERLIGHT
            case CryptographicPublicKeyBlobType.BCryptPublicKey:
                return(BCryptRsaPublicKey);
#endif
            default:
                throw new NotSupportedException();
            }
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, nameof(keyBlob));

            var              parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);
            BigInteger?      modulus = null, exponent = null;
            RSAPublicKeySpec?spec = null;

            try
            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                modulus  = new BigInteger(1, parameters.Modulus);
                exponent = new BigInteger(1, parameters.Exponent);
                spec     = new RSAPublicKeySpec(modulus, exponent);
#pragma warning restore CA2000 // Dispose objects before losing scope
                KeyFactory?factory = KeyFactory.GetInstance("RSA");
                if (factory is null)
                {
                    throw new InvalidOperationException(Strings.UnsupportedAlgorithm);
                }

                IPublicKey?publicKey = factory.GeneratePublic(spec);
                if (publicKey is null)
                {
                    throw new InvalidOperationException("KeyFactory.GeneratePublic returned null.");
                }

                return(new RsaCryptographicKey(publicKey, parameters, this.algorithm));
            }
            catch
            {
                spec?.Dispose();
                modulus?.Dispose();
                exponent?.Dispose();
                throw;
            }
        }
Example #24
0
 public void PublicKeyFormat(CryptographicPublicKeyBlobType format)
 {
     var rsa = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaOaepSha1);
     var key = rsa.CreateKeyPair(512);
     byte[] serialized = key.ExportPublicKey(format);
     Assert.NotNull(serialized);
     Assert.NotEmpty(serialized);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BCryptRsaKeyFormatter"/> class.
 /// </summary>
 /// <param name="publicKeyType">Must always be <see cref="CryptographicPublicKeyBlobType.BCryptPublicKey"/></param>
 public BCryptRsaKeyFormatter(CryptographicPublicKeyBlobType publicKeyType)
 {
     Requires.Argument(publicKeyType == CryptographicPublicKeyBlobType.BCryptPublicKey, nameof(publicKeyType), "Not a BCrypt key blob format.");
     this.keyType = BCRYPT_RSAKEY_BLOB.MagicNumber.BCRYPT_RSAPUBLIC_MAGIC;
 }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);
            var spec = new RSAPublicKeySpec(new BigInteger(1, parameters.Modulus), new BigInteger(1, parameters.Exponent));
            KeyFactory factory = KeyFactory.GetInstance("RSA");
            IPublicKey publicKey = factory.GeneratePublic(spec);
            return new RsaCryptographicKey(publicKey, parameters, this.algorithm);
        }
Example #27
0
 /// <inheritdoc />
 public abstract byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo);
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return KeyFormatter.GetFormatter(blobType).Write(KeyFormatter.ToPCLParameters(this.key.ExportParameters(false)));
 }
Example #29
0
        /// <summary>
        /// Gets the platform-specific enum value for the given PCL enum value.
        /// </summary>
        /// <param name="blobType">The platform independent enum value for the blob type.</param>
        /// <returns>The platform-specific enum value for the equivalent blob type.</returns>
        internal static Platform.CryptographicPublicKeyBlobType GetPlatformKeyBlobType(CryptographicPublicKeyBlobType blobType)
        {
            switch (blobType)
            {
            case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
                return(Platform.CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo);

            case CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey:
                return(Platform.CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey);

            case CryptographicPublicKeyBlobType.BCryptPublicKey:
                return(Platform.CryptographicPublicKeyBlobType.BCryptPublicKey);

            case CryptographicPublicKeyBlobType.Capi1PublicKey:
                return(Platform.CryptographicPublicKeyBlobType.Capi1PublicKey);

            default:
                throw new NotSupportedException();
            }
        }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            RSAParameters parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob);

            // Inject the PKCS#1 public key into the KeyChain.
            string keyIdentifier = Guid.NewGuid().ToString();
            string publicKeyIdentifier = RsaCryptographicKey.GetPublicKeyIdentifierWithTag(keyIdentifier);
            var keyQueryDictionary = RsaCryptographicKey.CreateKeyQueryDictionary(publicKeyIdentifier);
            keyQueryDictionary[KSec.ValueData] = NSData.FromArray(KeyFormatter.Pkcs1PrependZeros.Write(parameters, includePrivateKey: false));
            keyQueryDictionary[KSec.AttrKeyClass] = KSec.AttrKeyClassPublic;
            keyQueryDictionary[KSec.ReturnRef] = NSNumber.FromBoolean(true);
            IntPtr resultHandle;
            int status = RsaCryptographicKey.SecItemAdd(keyQueryDictionary.Handle, out resultHandle);
            if (resultHandle != IntPtr.Zero)
            {
                var key = new SecKey(resultHandle, true);
                return new RsaCryptographicKey(key, keyIdentifier, this.Algorithm);
            }
            else
            {
                throw new InvalidOperationException("SecItemAdd return " + status);
            }
        }
 /// <summary>
 /// Gets the platform-specific enum value for the given PCL enum value.
 /// </summary>
 /// <param name="blobType">The platform independent enum value for the blob type.</param>
 /// <returns>The platform-specific enum value for the equivalent blob type.</returns>
 internal static CngKeyBlobFormat GetPlatformKeyBlobType(CryptographicPublicKeyBlobType blobType)
 {
     switch (blobType)
     {
         case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
             return CngKeyBlobFormat.GenericPublicBlob;
         default:
             throw new NotSupportedException();
     }
 }
Example #32
0
		/// <summary>
		/// Exports a public key to a buffer given a specified format.
		/// </summary>
		/// <param name="BlobType">A CryptographicPublicKeyBlobType enumeration value that specifies the format of the key in the buffer. The default value is X509SubjectPublicKeyInfo.</param>
		/// <returns>Buffer that contains the public key.</returns>
		public IBuffer ExportPublicKey( CryptographicPublicKeyBlobType BlobType )
		{
			throw new NotImplementedException();
		}
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     try
     {
         return this.key.ExportPublicKey(AsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType)).ToArray();
     }
     catch (NotImplementedException ex)
     {
         throw new NotSupportedException(ex.Message, ex);
     }
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
 {
     throw new NotImplementedException();
 }
Example #35
0
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return(this.key.Export(CngAsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType)));
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return(KeyFormatter.GetFormatter(blobType).Write(this.parameters, includePrivateKey: false));
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     throw new NotSupportedException();
 }
        /// <inheritdoc/>
        public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
        {
            Requires.NotNull(keyBlob, "keyBlob");

            var rsa = new Platform.RSACryptoServiceProvider();
            rsa.ImportParameters(KeyFormatter.ToPlatformParameters(KeyFormatter.GetFormatter(blobType).Read(keyBlob)));
            return new RsaCryptographicKey(rsa, this.algorithm);
        }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return KeyFormatter.GetFormatter(blobType).Write(this.parameters, includePrivateKey: false);
 }
Example #40
0
 /// <inheritdoc />
 public abstract byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType);
 /// <summary>
 /// Gets the platform-specific enum value for the given PCL enum value.
 /// </summary>
 /// <param name="blobType">The platform independent enum value for the blob type.</param>
 /// <returns>The platform-specific enum value for the equivalent blob type.</returns>
 internal static Platform.CryptographicPublicKeyBlobType GetPlatformKeyBlobType(CryptographicPublicKeyBlobType blobType)
 {
     switch (blobType)
     {
         case CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo:
             return Platform.CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo;
         case CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey:
             return Platform.CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey;
         case CryptographicPublicKeyBlobType.BCryptPublicKey:
             return Platform.CryptographicPublicKeyBlobType.BCryptPublicKey;
         case CryptographicPublicKeyBlobType.Capi1PublicKey:
             return Platform.CryptographicPublicKeyBlobType.Capi1PublicKey;
         default:
             throw new NotSupportedException();
     }
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     byte[] keyData = KeyDataWithTag(GetPublicKeyIdentifierWithTag(this.keyIdentifier)).ToArray();
     RSAParameters parameters = KeyFormatter.Pkcs1.Read(keyData);
     return KeyFormatter.GetFormatter(blobType).Write(parameters);
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return this.key.Export(CngAsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType));
 }
Example #44
0
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     return(KeyFormatter.GetFormatter(blobType).Write(KeyFormatter.ToPCLParameters(this.key.ExportParameters(false))));
 }
 /// <inheritdoc />
 public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo)
 {
     throw new NotSupportedException();
 }
Example #46
0
 /// <inheritdoc />
 public override byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType)
 {
     throw new NotSupportedException();
 }