Пример #1
0
        public static BCryptRsaKeyBlob Load(byte[] buffer)
        {
            BCryptRsaKeyBlob result = new BCryptRsaKeyBlob();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(buffer)))
            {
                result.Magic       = reader.ReadUInt32();
                result.BitLength   = reader.ReadUInt32();
                result.cbPublicExp = reader.ReadUInt32();
                result.cbModulus   = reader.ReadUInt32();
                result.cbPrime1    = reader.ReadUInt32();
                result.cbPrime2    = reader.ReadUInt32();
            }

            return(result);
        }
Пример #2
0
        public RSAParameters ExportParameters(bool includePrivateParameters)
        {
#if WINDOWS_STORE
            IBuffer export = keyPair.Export(CryptographicPrivateKeyBlobType.BCryptPrivateKey);

            byte[] result;
            CryptographicBuffer.CopyToByteArray(export, out result);

            BCryptRsaKeyBlob header = BCryptRsaKeyBlob.Load(result);
            int offset = Marshal.SizeOf <BCryptRsaKeyBlob>();

            byte[] exponent = result.Skip(offset).Take((int)header.cbPublicExp).ToArray();

            offset += (int)header.cbPublicExp;
            byte[] modulus = result.Skip(offset).Take((int)header.cbModulus).ToArray();

            return(new RSAParameters(exponent, modulus));
#else
            System.Security.Cryptography.RSAParameters parameters =
                provider.ExportParameters(includePrivateParameters);

            return(new RSAParameters(parameters.Exponent, parameters.Modulus));
#endif
        }