public ChunkedCipherInputStream(DocumentInputStream dis, long size, AgileDecryptor ag) { try { _size = size; _stream = dis; _ag = ag; _cipher = _ag.GetCipher(_ag.Info.Header.Algorithm, _ag.Info.Header.CipherMode, _ag.SecretKey, _ag.Info.Header.KeySalt); } catch (System.Security.Cryptography.CryptographicException ex) { throw ex; } }
public void TestCertificateEncryption1() { POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.Agile, CipherAlgorithm.aes128, HashAlgorithm.sha1, -1, -1, ChainingMode.cbc); AgileEncryptionVerifier aev = (AgileEncryptionVerifier)info.Verifier; CertData certData = loadKeystore(); aev.AddCertificate(certData.x509); Encryptor enc = info.Encryptor; enc.ConfirmPassword("foobaa"); FileStream file = POIDataSamples.GetDocumentInstance().GetFile("VariousPictures.docx"); //InputStream fis = new FileInputStream(file); byte[] byteExpected = IOUtils.ToByteArray(file); //fis.Close(); Stream os = enc.GetDataStream(fs); IOUtils.Copy(new MemoryStream(byteExpected), os); os.Close(); MemoryStream bos = new MemoryStream(); fs.WriteFileSystem(bos); bos.Close(); fs = new POIFSFileSystem(new MemoryStream(bos.ToArray())); info = new EncryptionInfo(fs); AgileDecryptor agDec = (AgileDecryptor)info.Decryptor; bool passed = agDec.VerifyPassword(certData.keypair, certData.x509); Assert.IsTrue(passed, "certificate verification failed"); Stream fis = agDec.GetDataStream(fs); byte[] byteActual = IOUtils.ToByteArray(fis); fis.Close(); Assert.That(byteExpected, Is.EqualTo(byteActual)); }
public ChunkedCipherInputStream(DocumentInputStream dis, long size, AgileDecryptor ag) { try { _size = size; _stream = dis; _ag = ag; _cipher = _ag.GetCipher(_ag.Info.Header.Algorithm, _ag.Info.Header.CipherMode, _ag.SecretKey, _ag.Info.Header.KeySalt); } catch (System.Security.Cryptography.CryptographicException ex) { throw ex; } }