/// <summary>
        /// Imports a blob that represents asymmetric key information.
        /// </summary>
        /// <param name="rawData">A byte array that represents an asymmetric key blob.</param>
        /// <exception cref="CryptographicException">Invalid key blob data</exception>
        /// <returns>Initialized RSAParameters structure</returns>
        public void ImportCspBlob(byte[] rawData)
        {
            using (var stream = new MemoryStream(rawData))
            {
                using (var reader = new BinaryReader(stream))
                {
                    BlobHeader header = BlobHeader.FromBinary(reader);

                    if (header.BlobType == KeyBlobType.PublicKeyBlob)
                    {
                        this.ImportParameters(PublicKeyBlob.FromBinary(reader, header).ToRSAParameters());
                        return;
                    }

                    if (header.BlobType == KeyBlobType.PrivateKeyBlob)
                    {
                        this.ImportParameters(PrivateKeyBlob.FromBinary(reader, header).ToRSAParameters());
                        return;
                    }
                }
            }

            throw new CryptographicException("Invalid key blob data");
        }
Exemple #2
0
        /// <summary>
        /// Create and initialize structure from binary data
        /// </summary>
        /// <exception cref="CryptographicException">On validate errors</exception>
        /// <returns>Initialized structure</returns>
        public static PublicKeyBlob FromBinary(BinaryReader reader)
        {
            BlobHeader header = BlobHeader.FromBinary(reader);

            return(FromBinary(reader, header));
        }
Exemple #3
0
        /// <summary>
        /// Create and initialize structure from binary data
        /// </summary>
        /// <exception cref="CryptographicException">On validate errors</exception>
        /// <returns>Initialized structure</returns>
        public static PrivateKeyBlob FromBinary(BinaryReader reader)
        {
            var header = BlobHeader.FromBinary(reader);

            return(FromBinary(reader, header));
        }