public virtual void SetUp() { cert = new CertificateX509(); key = new PrivateKeyManager(); options = new JWTOptions(); claims = new PrivateClaims(); du = new DateUtil(); jwt = new JWTCreator(); cert.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256_cert.crt"); options.SetCertificate(cert); key.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256d_key.pem"); options.SetPrivateKey(key); // // carga de privateClaim (es parte del Payload) claims.setClaim("GeneXus", "Viglia"); // Carga de Registered Claims options.AddRegisteredClaim("iss", "Martin"); options.AddRegisteredClaim("sub", "Martin1"); options.AddRegisteredClaim("aud", "martivigliadoocebbooyo.docebosaas.com"); options.AddCustomTimeValidationClaim("iat", du.GetCurrentDate(), "20"); options.AddCustomTimeValidationClaim("exp", du.CurrentPlusSeconds(3600), "20"); options.AddPublicClaim("client_id", "Martin"); token = jwt.DoCreate("RS256", claims, options); expected = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"; }
public virtual void SetUp() { options1 = new JWTOptions(); options2 = new JWTOptions(); jwt = new JWTCreator(); claims = new PrivateClaims(); claims.setClaim("hola1", "hola1"); path_RSA_sha256_1024 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha256_1024"); String pathKey = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem"); String pathCert = Path.Combine(path_RSA_sha256_1024, "sha256_cert.crt"); PrivateKeyManager key = new PrivateKeyManager(); CertificateX509 cert = new CertificateX509(); key.Load(pathKey); cert.Load(pathCert); options1.SetCertificate(cert); options1.SetPrivateKey(key); options1.AddRegisteredClaim("iss", "GXSA"); options1.AddRegisteredClaim("sub", "subject1"); options1.AddRegisteredClaim("aud", "audience1"); options2.AddRegisteredClaim("iss", "GXSA"); options2.AddRegisteredClaim("sub", "subject1"); options2.AddRegisteredClaim("aud", "audience1"); options2.SetCertificate(cert); token = jwt.DoCreate("RS256", claims, options1); }
public void TestExport() { PrivateKeyManager pkm = new PrivateKeyManager(); pkm.Load(path); string base64res = pkm.ToBase64(); Assert.IsTrue(SecurityUtils.compareStrings(base64res, base64string)); Assert.IsFalse(pkm.HasError()); }
public void Test_sha256_1024_DER() { string pathKey = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem"); string pathCert = Path.Combine(path_RSA_sha256_1024, "sha256_cert.crt"); PrivateKeyManager key = new PrivateKeyManager(); key.Load(pathKey); CertificateX509 cert = new CertificateX509(); cert.Load(pathCert); runTestWithEncoding(key, cert, "SHA256"); }
public void Test_sha512_2048_PEM() { string pathKey = Path.Combine(path_RSA_sha512_2048, "sha512d_key.pem"); string pathCert = Path.Combine(path_RSA_sha512_2048, "sha512_cert.pem"); PrivateKeyManager key = new PrivateKeyManager(); key.Load(pathKey); CertificateX509 cert = new CertificateX509(); cert.Load(pathCert); runTestWithEncoding(key, cert, "SHA512"); }
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_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 Test_sha256_1024_PEM() { String pathKey = Path.Combine(path_RSA_sha256_1024, "sha256d_key.pem"); PrivateKeyManager key = new PrivateKeyManager(); key.Load(pathKey); options.SetPrivateKey(key); String alg = "RS256"; String token = jwt.DoCreate(alg, claims, options); Assert.IsFalse(SecurityUtils.compareStrings("", token)); Assert.IsFalse(jwt.HasError()); }
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); }
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); }
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 }
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); } }
public void TestSignBase64() { CertificateX509 newCert = new CertificateX509(); bool loaded = newCert.FromBase64(base64); Assert.IsTrue(loaded); True(loaded, newCert); PrivateKeyManager key = new PrivateKeyManager(); bool privateLoaded = key.Load(pathKey); Assert.IsTrue(privateLoaded); True(privateLoaded, key); XmlDSigSigner signer = new XmlDSigSigner(); bool result = signer.DoSignFile(xmlUnsignedPath, key, newCert, xmlSignedPathRoot + pathSigned, options); Assert.IsTrue(result); True(result, signer); bool verify = signer.DoVerifyFile(xmlSignedPathRoot + pathSigned, options); Assert.IsTrue(verify); True(verify, signer); }