Esempio n. 1
0
            // methods

            private void Decode(byte[] data)
            {
                ASN1 encryptedPrivateKeyInfo = new ASN1(data);

                if (encryptedPrivateKeyInfo.Tag != 0x30)
                {
                    throw new CryptographicException("invalid EncryptedPrivateKeyInfo");
                }

                ASN1 encryptionAlgorithm = encryptedPrivateKeyInfo[0];

                if (encryptionAlgorithm.Tag != 0x30)
                {
                    throw new CryptographicException("invalid encryptionAlgorithm");
                }
                ASN1 algorithm = encryptionAlgorithm[0];

                if (algorithm.Tag != 0x06)
                {
                    throw new CryptographicException("invalid algorithm");
                }
                _algorithm = ASN1Convert.ToOid(algorithm);
                // parameters ANY DEFINED BY algorithm OPTIONAL
                if (encryptionAlgorithm.Count > 1)
                {
                    ASN1 parameters = encryptionAlgorithm[1];
                    if (parameters.Tag != 0x30)
                    {
                        throw new CryptographicException("invalid parameters");
                    }

                    ASN1 salt = parameters[0];
                    if (salt.Tag != 0x04)
                    {
                        throw new CryptographicException("invalid salt");
                    }
                    _salt = salt.Value;

                    ASN1 iterationCount = parameters[1];
                    if (iterationCount.Tag != 0x02)
                    {
                        throw new CryptographicException("invalid iterationCount");
                    }
                    _iterations = ASN1Convert.ToInt32(iterationCount);
                }

                ASN1 encryptedData = encryptedPrivateKeyInfo[1];

                if (encryptedData.Tag != 0x04)
                {
                    throw new CryptographicException("invalid EncryptedData");
                }
                _data = encryptedData.Value;
            }
Esempio n. 2
0
            // methods

            private void Decode(byte[] data)
            {
                ASN1 privateKeyInfo = new ASN1(data);

                if (privateKeyInfo.Tag != 0x30)
                {
                    throw new CryptographicException("invalid PrivateKeyInfo");
                }

                ASN1 version = privateKeyInfo[0];

                if (version.Tag != 0x02)
                {
                    throw new CryptographicException("invalid version");
                }
                _version = version.Value[0];

                ASN1 privateKeyAlgorithm = privateKeyInfo[1];

                if (privateKeyAlgorithm.Tag != 0x30)
                {
                    throw new CryptographicException("invalid algorithm");
                }

                ASN1 algorithm = privateKeyAlgorithm[0];

                if (algorithm.Tag != 0x06)
                {
                    throw new CryptographicException("missing algorithm OID");
                }
                _algorithm = ASN1Convert.ToOid(algorithm);

                ASN1 privateKey = privateKeyInfo[2];

                _key = privateKey.Value;

                // attributes [0] IMPLICIT Attributes OPTIONAL
                if (privateKeyInfo.Count > 3)
                {
                    ASN1 attributes = privateKeyInfo[3];
                    for (int i = 0; i < attributes.Count; i++)
                    {
                        _list.Add(attributes[i]);
                    }
                }
            }