/// <summary> /// Create and initialize structure from binary data with defined header /// </summary> /// <exception cref="CryptographicException">On validate errors</exception> /// <returns>Initialized structure</returns> public static PrivateKeyBlob FromBinary(BinaryReader reader, BlobHeader header) { var privateKeyBlob = new PrivateKeyBlob { Header = header, RSAPubKey = RSAPubKey.FromBinary(reader), }; int byteLength = (int)(privateKeyBlob.RSAPubKey.BitLength >> 3); int wordLength = (int)(privateKeyBlob.RSAPubKey.BitLength >> 4); privateKeyBlob.Modulus = new byte[byteLength]; reader.Read(privateKeyBlob.Modulus, 0, privateKeyBlob.Modulus.Length); privateKeyBlob.Prime1 = new byte[wordLength]; reader.Read(privateKeyBlob.Prime1, 0, privateKeyBlob.Prime1.Length); privateKeyBlob.Prime2 = new byte[wordLength]; reader.Read(privateKeyBlob.Prime2, 0, privateKeyBlob.Prime2.Length); privateKeyBlob.Exponent1 = new byte[wordLength]; reader.Read(privateKeyBlob.Exponent1, 0, privateKeyBlob.Exponent1.Length); privateKeyBlob.Exponent2 = new byte[wordLength]; reader.Read(privateKeyBlob.Exponent2, 0, privateKeyBlob.Exponent2.Length); privateKeyBlob.Coefficient = new byte[wordLength]; reader.Read(privateKeyBlob.Coefficient, 0, privateKeyBlob.Coefficient.Length); privateKeyBlob.PrivateExponent = new byte[byteLength]; reader.Read(privateKeyBlob.PrivateExponent, 0, privateKeyBlob.PrivateExponent.Length); return(privateKeyBlob); }
/// <summary> /// Create and initialize structure from binary data with defined header /// </summary> /// <exception cref="CryptographicException">On validate errors</exception> /// <returns>Initialized structure</returns> public static PublicKeyBlob FromBinary(BinaryReader reader, BlobHeader header) { var publicKeyBlob = new PublicKeyBlob { Header = header, RSAPubKey = RSAPubKey.FromBinary(reader), }; int modulusLength = (int)(publicKeyBlob.RSAPubKey.BitLength >> 3); publicKeyBlob.Modulus = new byte[modulusLength]; reader.Read(publicKeyBlob.Modulus, 0, publicKeyBlob.Modulus.Length); return(publicKeyBlob); }