Exemplo n.º 1
0
        public override byte[] ToPvk()
        {
            var blob = new RsaPrivateKeyBlob(ToRsaParameters());
            var key  = blob.ToArray();
            var pvk  = new PrivateKeyFile {
                KeyType   = 2,
                Encrypted = 0,
                SaltLen   = 0,
                Key       = key
            };

            return(pvk.ToArray());
        }
Exemplo n.º 2
0
        public static RsaPrivateKeyBlob Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) {
                var res = new RsaPrivateKeyBlob {
                    Type     = reader.ReadByte(),
                    Version  = reader.ReadByte(),
                    Reserved = reader.ReadUInt16(),
                    KeyAlg   = reader.ReadUInt32(),
                    Magic    = reader.ReadUInt32(),
                    BitLen   = reader.ReadUInt32(),
                    PubExp   = reader.ReadUInt32()
                };

                res.Modulus = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 8.0));
                res.P       = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 16.0));
                res.Q       = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 16.0));
                res.Dp      = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 16.0));
                res.Dq      = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 16.0));
                res.Iq      = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 16.0));
                res.D       = reader.ReadBytes((int)Math.Ceiling(res.BitLen / 8.0));
                return(res);
            }
        }