public Open ( Stream outStream, string compressionOID ) : Stream | ||
outStream | Stream | |
compressionOID | string | |
리턴 | Stream |
public void TestEach() { byte[] testData = Encoding.ASCII.GetBytes("Hello world!"); CmsCompressedDataStreamGenerator gen = new CmsCompressedDataStreamGenerator(); MemoryStream bOut = new MemoryStream(); Stream cOut = gen.Open(bOut, CmsCompressedDataStreamGenerator.ZLib); cOut.Write(testData, 0, testData.Length); cOut.Close(); CmsCompressedDataParser ed = new CmsCompressedDataParser(bOut.ToArray()); Assert.IsTrue(Arrays.AreEqual(testData, CmsTestUtil.StreamToByteArray(ed.GetContent().ContentStream))); }
public void Test1000() { byte[] testData = new byte[10000]; SecureRandom rand = new SecureRandom(); rand.SetSeed(0); for (int i = 0; i != 10; i++) { CmsCompressedDataStreamGenerator gen = new CmsCompressedDataStreamGenerator(); MemoryStream bOut = new MemoryStream(); Stream cOut = gen.Open(bOut, CmsCompressedDataStreamGenerator.ZLib); rand.NextBytes(testData); cOut.Write(testData, 0, testData.Length); cOut.Close(); CmsCompressedDataParser ed = new CmsCompressedDataParser(bOut.ToArray()); Assert.IsTrue(Arrays.AreEqual(testData, CmsTestUtil.StreamToByteArray(ed.GetContent().ContentStream))); } }
public void TestSha1WithRsa() { IList certList = new ArrayList(); IList crlList = new ArrayList(); MemoryStream bOut = new MemoryStream(); certList.Add(OrigCert); certList.Add(SignCert); crlList.Add(SignCrl); crlList.Add(OrigCrl); IX509Store x509Certs = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(certList)); IX509Store x509Crls = X509StoreFactory.Create( "CRL/Collection", new X509CollectionStoreParameters(crlList)); CmsSignedDataStreamGenerator gen = new CmsSignedDataStreamGenerator(); gen.AddSigner(OrigKP.Private, OrigCert, CmsSignedDataStreamGenerator.DigestSha1); gen.AddCertificates(x509Certs); gen.AddCrls(x509Crls); Stream sigOut = gen.Open(bOut); CmsCompressedDataStreamGenerator cGen = new CmsCompressedDataStreamGenerator(); Stream cOut = cGen.Open(sigOut, CmsCompressedDataStreamGenerator.ZLib); byte[] testBytes = Encoding.ASCII.GetBytes(TestMessage); cOut.Write(testBytes, 0, testBytes.Length); cOut.Close(); sigOut.Close(); CheckSigParseable(bOut.ToArray()); // generate compressed stream MemoryStream cDataOut = new MemoryStream(); cOut = cGen.Open(cDataOut, CmsCompressedDataStreamGenerator.ZLib); cOut.Write(testBytes, 0, testBytes.Length); cOut.Close(); CmsSignedDataParser sp = new CmsSignedDataParser( new CmsTypedStream(new MemoryStream(cDataOut.ToArray(), false)), bOut.ToArray()); sp.GetSignedContent().Drain(); // // compute expected content digest // IDigest md = DigestUtilities.GetDigest("SHA1"); byte[] cDataOutBytes = cDataOut.ToArray(); md.BlockUpdate(cDataOutBytes, 0, cDataOutBytes.Length); byte[] hash = DigestUtilities.DoFinal(md); VerifySignatures(sp, hash); }