private PgpSecretKeyRing loadSecretKey( string keyName) { Stream fIn = SimpleTest.GetTestDataAsStream("openpgp.dsa.keys." + keyName); return(new PgpSecretKeyRing(fIn)); }
private PgpObjectFactory loadSig( string sigName) { Stream fIn = SimpleTest.GetTestDataAsStream("openpgp.dsa.sigs." + sigName); return(new PgpObjectFactory(fIn)); }
private X509Certificate LoadCert( string certName) { X509Certificate cert = (X509Certificate)certs[certName]; if (cert != null) { return(cert); } Stream fs = null; try { fs = SimpleTest.GetTestDataAsStream("PKITS.certs." + certName + ".crt"); cert = new X509CertificateParser().ReadCertificate(fs); certs[certName] = cert; return(cert); } catch (Exception e) { throw new InvalidOperationException("exception loading certificate " + certName + ": " + e); } finally { fs.Close(); } }
private X509Crl LoadCrl( string crlName) //throws Exception { X509Crl crl = (X509Crl)certs[crlName]; if (crl != null) { return(crl); } Stream fs = null; try { fs = SimpleTest.GetTestDataAsStream("PKITS.crls." + crlName + ".crl"); crl = new X509CrlParser().ReadCrl(fs); crls[crlName] = crl; return(crl); } catch (Exception) { throw new InvalidOperationException("exception loading CRL: " + crlName); } finally { fs.Close(); } }
private void RunTests(IStreamCipher hc, string fileName) { Stream resource = SimpleTest.GetTestDataAsStream( "hc256." + fileName.Replace('/', '.')); PeekableLineReader r = new PeekableLineReader(resource); RunAllVectors(hc, fileName, r); }
private X509Certificate loadCert( string certName) { Stream s = SimpleTest.GetTestDataAsStream("rsa3." + certName); TextReader tr = new StreamReader(s); PemReader rd = new PemReader(tr); return((X509Certificate)rd.ReadObject()); }
internal static PemObject LoadPemResource(string resource) { Stream s = SimpleTest.GetTestDataAsStream("tls." + resource); PemReader p = new PemReader(new StreamReader(s)); PemObject o = p.ReadPemObject(); p.Reader.Close(); return(o); }
public IEnumerable CollectTestVectors() { ArrayList testVectors = new ArrayList(); string curve = null; BigInteger k = null; BigInteger x = null; BigInteger y = null; using (StreamReader r = new StreamReader(SimpleTest.GetTestDataAsStream("crypto.nist_ecc.txt"))) { string line; while (null != (line = r.ReadLine())) { Regex capture = new Regex(@"^ ?(\w+):? =? ?(\w+)", RegexOptions.Compiled); Match data = capture.Match(line); if (!data.Success) { continue; } string nistKey = data.Groups[1].Value; string nistValue = data.Groups[2].Value; switch (nistKey) { case "Curve": // Change curve name from LNNN to L-NNN ie: P256 to P-256 curve = nistValue.Insert(1, "-"); break; case "k": k = new BigInteger(nistValue, 10); break; case "x": x = new BigInteger(nistValue, 16); break; case "y": y = new BigInteger(nistValue, 16); break; } if (null != curve && null != k && null != x && null != y) { testVectors.Add(new object[] { curve, k, x, y }); k = null; x = null; y = null; } } } return(testVectors); }
public void TestVectors() { using (StreamReader r = new StreamReader(SimpleTest.GetTestDataAsStream("crypto.SHA3TestVectors.txt"))) { String line; while (null != (line = ReadLine(r))) { if (line.Length != 0) { TestVector v = ReadTestVector(r, line); RunTestVector(v); } } } }
public void TestVectors() { using (StreamReader sr = new StreamReader(SimpleTest.GetTestDataAsStream("scrypt.TestVectors.txt"))) { int count = 0; string line = sr.ReadLine(); while (line != null) { ++count; string header = line; StringBuilder data = new StringBuilder(); while (!IsEndData(line = sr.ReadLine())) { data.Append(line.Replace(" ", "")); } int start = header.IndexOf('(') + 1; int limit = header.LastIndexOf(')'); string argStr = header.Substring(start, limit - start); string[] args = argStr.Split(','); byte[] P = ExtractQuotedString(args[0]); byte[] S = ExtractQuotedString(args[1]); int N = ExtractInteger(args[2]); int r = ExtractInteger(args[3]); int p = ExtractInteger(args[4]); int dkLen = ExtractInteger(args[5]); byte[] expected = Hex.Decode(data.ToString()); // This skips very expensive test case(s), remove check to re-enable if (N <= 16384) { byte[] result = SCrypt.Generate(P, S, N, r, p, dkLen); if (!AreEqual(expected, result)) { Fail("Result does not match expected value in test case " + count); } } } } }
public void TestCyrillicPassphrase() { try { BigInteger keyId = new BigInteger("B7773AF32BE4EC1806B1BACC4680E7F3960C44E7", 16); // XXX The password text file must not have the UTF-8 BOM ! // Ref: http://stackoverflow.com/questions/2223882/whats-different-between-utf-8-and-utf-8-without-bom Stream passwordFile = SimpleTest.GetTestDataAsStream("openpgp.unicode.passphrase_cyr.txt"); TextReader reader = new StreamReader(passwordFile, Encoding.UTF8); string passphrase = reader.ReadLine(); passwordFile.Close(); DoTestKey(keyId, passphrase, true); // all fine! } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); Assert.Fail(e.Message); } }
public static ArrayList ReadVectorFile(string name) { ArrayList vectors = new ArrayList(); Hashtable header = null; Vector currentVector = null; int headerState = 0; using (StreamReader r = new StreamReader(SimpleTest.GetTestDataAsStream("crypto.cavp." + name))) { String line; while (null != (line = r.ReadLine())) { // Reading a header or waiting to encounter a header // and we encounter a vector line. // Set up a new vector. if (headerState <= 1 && !line.StartsWith("[") && Contains(line, '=')) { currentVector = new Vector(header); vectors.Add(currentVector); headerState = 2; } // // Read // if (headerState == 2) { // // Header line found immediately after vector elements. // if (line.StartsWith("[") && line.EndsWith("]")) { headerState = 0; } else // // Not a valid line so we assume this is a break between vectors. // if (headerState == 2 && !Contains(line, '=')) { headerState = 0; } else // // Vector parameter. // if (!line.StartsWith("[") && Contains(line, '=')) { if (currentVector == null) { currentVector = new Vector(header); vectors.Add(currentVector); } string[] parts = line.Split('='); currentVector[parts[0].Trim()] = parts[1].Trim(); headerState = 2; } } // // Found start of header block. // We need a new header map. // if (headerState == 0 && line.StartsWith("[") && line.EndsWith("]")) { header = new Hashtable(); headerState = 1; } // // Read header lines. // if (headerState <= 1) { if (line.StartsWith("[") && line.EndsWith("]")) { // Strip away brackets. string trimmed = line.Substring(1, line.Length - 2); string[] parts = trimmed.Split('='); header[parts[0].Trim()] = parts[1].Trim(); headerState = 1; } } } } return(vectors); }
private PgpSecretKeyRingBundle LoadSecretKeyCollection(string keyName) { return(new PgpSecretKeyRingBundle(SimpleTest.GetTestDataAsStream("openpgp.unicode." + keyName))); }
private Stream loadSig(string sigName) { return(SimpleTest.GetTestDataAsStream("openpgp.dsa.sigs." + sigName)); }
private static byte[] GetRfc4134Data(string name) { return(Streams.ReadAll(SimpleTest.GetTestDataAsStream("rfc4134." + name))); }
private byte[] GetInput(string name) { return(Streams.ReadAll(SimpleTest.GetTestDataAsStream("asn1." + name))); }
public override void PerformTest() { Stream fIn = SimpleTest.GetTestDataAsStream("openpgp.bigpub.asc"); Stream keyIn = PgpUtilities.GetDecoderStream(fIn); PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(keyIn); }
public void BigPub() { using Stream fIn = SimpleTest.GetTestDataAsStream("openpgp.bigpub.asc"); //using Stream keyIn = new ArmoredInputStream(fIn); PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(new ArmoredPacketReader(fIn)); }