Esempio n. 1
0
        private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8)
        {
            RSACryptoServiceProvider rSACryptoServiceProvider;

            byte[]       numArray     = new byte[] { 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0 };
            byte[]       numArray1    = new byte[15];
            MemoryStream memoryStream = new MemoryStream(pkcs8);
            int          length       = (int)memoryStream.Length;
            BinaryReader binaryReader = new BinaryReader(memoryStream);
            byte         num          = 0;
            ushort       num1         = 0;

            try
            {
                try
                {
                    num1 = binaryReader.ReadUInt16();
                    if (num1 == 33072)
                    {
                        binaryReader.ReadByte();
                    }
                    else if (num1 != 33328)
                    {
                        rSACryptoServiceProvider = null;
                        return(rSACryptoServiceProvider);
                    }
                    else
                    {
                        binaryReader.ReadInt16();
                    }
                    num = binaryReader.ReadByte();
                    if (num == 2)
                    {
                        num1 = binaryReader.ReadUInt16();
                        if (num1 != 1)
                        {
                            rSACryptoServiceProvider = null;
                        }
                        else if (RSAFromPkcs8.CompareBytearrays(binaryReader.ReadBytes(15), numArray))
                        {
                            num = binaryReader.ReadByte();
                            if (num == 4)
                            {
                                num = binaryReader.ReadByte();
                                if (num == 129)
                                {
                                    binaryReader.ReadByte();
                                }
                                else if (num == 130)
                                {
                                    binaryReader.ReadUInt16();
                                }
                                byte[] numArray2 = binaryReader.ReadBytes((int)((long)length - memoryStream.Position));
                                rSACryptoServiceProvider = RSAFromPkcs8.DecodeRSAPrivateKey(numArray2);
                            }
                            else
                            {
                                rSACryptoServiceProvider = null;
                            }
                        }
                        else
                        {
                            rSACryptoServiceProvider = null;
                        }
                    }
                    else
                    {
                        rSACryptoServiceProvider = null;
                    }
                }
                catch (Exception exception)
                {
                    rSACryptoServiceProvider = null;
                }
            }
            finally
            {
                binaryReader.Close();
            }
            return(rSACryptoServiceProvider);
        }
Esempio n. 2
0
        private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8)
        {
            byte[] b = new byte[]
            {
                48,
                13,
                6,
                9,
                42,
                134,
                72,
                134,
                247,
                13,
                1,
                1,
                1,
                5,
                0
            };
            byte[]                   a            = new byte[15];
            MemoryStream             memoryStream = new MemoryStream(pkcs8);
            int                      num          = (int)memoryStream.Length;
            BinaryReader             binaryReader = new BinaryReader(memoryStream);
            RSACryptoServiceProvider result;

            try
            {
                ushort num2 = binaryReader.ReadUInt16();
                if (num2 == 33072)
                {
                    binaryReader.ReadByte();
                }
                else
                {
                    if (num2 != 33328)
                    {
                        result = null;
                        return(result);
                    }
                    binaryReader.ReadInt16();
                }
                byte b2 = binaryReader.ReadByte();
                if (b2 != 2)
                {
                    result = null;
                }
                else
                {
                    num2 = binaryReader.ReadUInt16();
                    if (num2 != 1)
                    {
                        result = null;
                    }
                    else
                    {
                        a = binaryReader.ReadBytes(15);
                        if (!RSAFromPkcs8.CompareBytearrays(a, b))
                        {
                            result = null;
                        }
                        else
                        {
                            b2 = binaryReader.ReadByte();
                            if (b2 != 4)
                            {
                                result = null;
                            }
                            else
                            {
                                b2 = binaryReader.ReadByte();
                                if (b2 == 129)
                                {
                                    binaryReader.ReadByte();
                                }
                                else if (b2 == 130)
                                {
                                    binaryReader.ReadUInt16();
                                }
                                byte[] privkey = binaryReader.ReadBytes((int)((long)num - memoryStream.Position));
                                RSACryptoServiceProvider rSACryptoServiceProvider = RSAFromPkcs8.DecodeRSAPrivateKey(privkey);
                                result = rSACryptoServiceProvider;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                result = null;
            }
            finally
            {
                binaryReader.Close();
            }
            return(result);
        }