Beispiel #1
0
        public void Test_sha256_2048_DER()
        {
            string            pathKey  = Path.Combine(path_RSA_sha256_2048, "sha256d_key.pem");
            string            pathCert = Path.Combine(path_RSA_sha256_2048, "sha256_cert.crt");
            PrivateKeyManager key      = new PrivateKeyManager();

            key.Load(pathKey);
            CertificateX509 cert = new CertificateX509();

            cert.Load(pathCert);
            runTestWithEncoding(key, cert, "SHA256");
        }
        public void Test_ecdsa_sha256_PEM()
        {
            string            pathKey  = Path.Combine(path_ecdsa_sha256, "sha256_key.pem");
            string            pathCert = Path.Combine(path_ecdsa_sha256, "sha256_cert.pem");
            PrivateKeyManager key      = new PrivateKeyManager();

            key.Load(pathKey);
            CertificateX509 cert = new CertificateX509();

            cert.Load(pathCert);
            runTestWithEncoding(key, cert, "SHA256");
        }
        public void Test_sha256_1024_PEM()
        {
            string            pathKey  = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem");
            string            pathCert = Path.Combine(path_RSA_sha256_1024, "sha256_cert.pem");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);
            string alg = "RS256";

            bulkTest(key, cert, alg);
        }
        public void Test_sha256_2048_PEM_Encrypted()
        {
            string            pathKey  = Path.Combine(path_RSA_sha256_2048, "sha256_key.pem");
            string            pathCert = Path.Combine(path_RSA_sha256_2048, "sha256_cert.pem");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.LoadEncrypted(pathKey, password);
            cert.Load(pathCert);
            string alg = "RS256";

            bulkTest(key, cert, alg);
        }
        public void Test_sha512_2048_DER()
        {
            string            pathKey  = Path.Combine(path_RSA_sha512_2048, "sha512d_key.pem");
            string            pathCert = Path.Combine(path_RSA_sha512_2048, "sha512_cert.crt");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);
            string alg = "RS512";

            bulkTest(key, cert, alg);
        }
        public void prime256v1()
        {
            string            pathKey  = Path.Combine(ECDSA_path, "prime256v1", "key.pem");
            string            pathCert = Path.Combine(ECDSA_path, "prime256v1", "cert.pem");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);
            string alg   = "ES256";
            string curve = "prime256v1";

            bulkTest_shouldWork(key, cert, alg, curve);
        }
Beispiel #7
0
        public void TestSpaces()
        {
            key.Load(pathKey);
            cert.Load(pathCert);
            string encrypted1 = asymCipher.DoEncrypt_WithPrivateKey("SHA1 ", "PCKS1PADDING ", key, plainText);

            //System.out.println("Error. Code: " + asymCipher.getErrorCode() + " Desc: " + asymCipher.getErrorDescription());
            Assert.IsFalse(asymCipher.HasError());

            string decrypted = asymCipher.DoDecrypt_WithPublicKey(" SHA1", " PCKS1PADDING", cert, encrypted1);

            Assert.IsFalse(asymCipher.HasError());
            Assert.IsTrue(SecurityUtils.compareStrings(plainText, decrypted));
        }
        public void sect113r1()
        {
            string            pathKey  = ECDSA_path + "sect113r1" + "\\key.pem";
            string            pathCert = ECDSA_path + "sect113r1" + "\\cert.pem";
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);
            string alg   = "ES256";
            string curve = "sect113r1";

            bulkTest_shouldntWork(key, cert, alg, curve);
        }
Beispiel #9
0
        public virtual void SetUp()
        {
            cert = new CertificateX509();
            cert.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256_cert.crt");
            key = new PrivateKeyManager();
            key.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256d_key.pem");

            signer  = new XmlDSigSigner();
            options = new DSigOptions();

            options.IdentifierAttribute = "Id";

            xmlInput = "<envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>1</idLote><evento versao=\"1.00\"><infEvento Id=\"ID2102103521011431017000298855005000016601157405784801\"><cOrgao>91</cOrgao><tpAmb>1</tpAmb><CNPJ>31102046000145</CNPJ><chNFe>35210114310170002988550050000166011574057848</chNFe><dhEvento>2021-01-26T11:12:34-03:00</dhEvento><tpEvento>210210</tpEvento><nSeqEvento>1</nSeqEvento><verEvento>1.00</verEvento><detEvento versao=\"1.00\"><descEvento>Ciencia da Operacao</descEvento></detEvento></infEvento></evento></envEvento>";
            xPath    = "#ID2102103521011431017000298855005000016601157405784801";
        }
        public void prime192v2()
        {
            string            pathKey  = Path.Combine(ECDSA_path, "prime192v2", "key.pem");
            string            pathCert = Path.Combine(ECDSA_path, "prime192v2", "cert.pem");
            PrivateKeyManager key      = new PrivateKeyManager();
            CertificateX509   cert     = new CertificateX509();

            key.Load(pathKey);
            cert.Load(pathCert);
            string alg   = "ES256";
            string curve = "prime192v2";

#if NETCORE
            bulkTest_shouldntWork(key, cert, alg, curve);
#else
            bulkTest_shouldWork(key, cert, alg, curve);
#endif
        }
Beispiel #11
0
        private void bulkTest(string pathCert, string pathKey, string pathSigned, bool ispkcs12, bool encrypted)
        {
            for (int k = 0; k < arrayKeyInfoType.Length; k++)
            {
                options.KeyInfoType      = arrayKeyInfoType[k];
                optionsXPath.KeyInfoType = arrayKeyInfoType[k];
                optionsID.KeyInfoType    = arrayKeyInfoType[k];
                CertificateX509 cert = new CertificateX509();
                if (ispkcs12)
                {
                    cert.LoadPKCS12(pathCert, alias, password);
                }
                else
                {
                    cert.Load(pathCert);
                }
                PrivateKeyManager key = new PrivateKeyManager();

                if (ispkcs12)
                {
                    key.LoadPKCS12(pathKey, alias, password);
                }
                else
                {
                    key.Load(pathKey);
                }

                /*if (ispkcs12)
                 * {
                 *      key.LoadPKCS12(pathKey, alias, password);
                 * }
                 * else if(encrypted)
                 * {
                 *      key.LoadEncrypted(pathKey, password);
                 * }else
                 * {
                 *      key.Load(pathKey);
                 * }*/

                bulkTestWithKeyInfo(cert, key, pathSigned);
                bulkTestWithKeyInfoXPath(cert, key, pathSigned);
                bulkTestWithKeyInfoID(cert, key, pathSigned);
            }
        }