Esempio n. 1
0
        public void ParseRsaPrivateKeyPkcs1_parses_openssl_generated_key_pem_file()
        {
            var pem = GetFixture("openssl-rsa-private-key", "pem");
            var rsa = Pem.ParseRsaPrivateKeyPkcs1(pem);

            VerifyRsaKey(rsa);
        }
Esempio n. 2
0
        public static (List <Account> Accounts, RSAParameters?PrivateKey) Parse(JObject json, string parentPath = "")
        {
            // The top-level item must be a folder
            var topLevel = GetFolderContent(json);

            if (topLevel == null)
            {
                throw new InternalErrorException("Invalid format: top level folder not found");
            }

            // There's a root folder somewhere at the second level
            var root = FindNamedItem(topLevel, "root");

            if (root == null || !IsFolder(root))
            {
                throw new InternalErrorException("Invalid format: root folder not found");
            }

            // Traverse the root folder recursively and parse all the accounts
            var accounts = new List <Account>();

            if (root["c"] is JArray c)
            {
                TraverseParse(c, parentPath, accounts);
            }

            // Parse the private key
            RSAParameters?rsa        = null;
            var           privateKey = FindNamedItem(topLevel, "private-key.pem").StringAt("b", "");

            if (!privateKey.IsNullOrEmpty())
            {
                rsa = Pem.ParseRsaPrivateKeyPkcs1(privateKey);
            }

            return(accounts, rsa);
        }
Esempio n. 3
0
        public void ParsePrivateKeyPkcs1_parses_openssl_generated_key()
        {
            var rsa = Pem.ParseRsaPrivateKeyPkcs1(PrivateKeyPkcs1);

            VerifyRsaKey(rsa);
        }