public void TestV1Document() { using (MemoryStream inputStream = new MemoryStream(Resources.david_copperfield_key__aa_ae_oe__ulu_txt)) { AxCryptFactory axFactory = new AxCryptFactory(); IEnumerable <DecryptionParameter> decryptionParameters = DecryptionParameter.CreateAll(new Passphrase[] { new Passphrase("Å ä Ö") }, null, new Guid[] { new V1Aes128CryptoFactory().CryptoId }); using (IAxCryptDocument decryptedDocument = axFactory.CreateDocument(decryptionParameters, inputStream)) { Assert.That(decryptedDocument.PassphraseIsValid); } } }
public static IEnumerable <DecryptionParameter> DecryptionParameters(this IDataStore dataStore, Passphrase password, IEnumerable <IAsymmetricPrivateKey> privateKeys) { if (privateKeys == null) { throw new ArgumentNullException(nameof(privateKeys)); } if (!dataStore.IsEncrypted()) { return(new DecryptionParameter[0]); } if (dataStore.IsLegacyV1()) { return(DecryptionParameter.CreateAll(new Passphrase[] { password }, privateKeys, new Guid[] { new V1Aes128CryptoFactory().CryptoId })); } return(DecryptionParameter.CreateAll(new Passphrase[] { password }, privateKeys, Resolve.CryptoFactory.OrderedIds.Where(id => id != new V1Aes128CryptoFactory().CryptoId))); }
public void TestV2Document() { using (MemoryStream inputStream = new MemoryStream()) { byte[] text = Resolve.RandomGenerator.Generate(500); inputStream.Write(text, 0, text.Length); inputStream.Position = 0; byte[] buffer = new byte[2500]; using (V2AxCryptDocument document = new V2AxCryptDocument(new EncryptionParameters(new V2Aes256CryptoFactory().CryptoId, new Passphrase("properties")), 15)) { document.EncryptTo(inputStream, new MemoryStream(buffer), AxCryptOptions.EncryptWithCompression); } AxCryptFactory axFactory = new AxCryptFactory(); IEnumerable <DecryptionParameter> decryptionParameters = DecryptionParameter.CreateAll(new Passphrase[] { new Passphrase("properties") }, null, new Guid[] { new V2Aes256CryptoFactory().CryptoId }); using (IAxCryptDocument decryptedDocument = axFactory.CreateDocument(decryptionParameters, new MemoryStream(buffer))) { Assert.That(decryptedDocument.PassphraseIsValid); } } }
public static IEnumerable <DecryptionParameter> DecryptionParameters(this LogOnIdentity identity) { IEnumerable <DecryptionParameter> decryptionParameters = DecryptionParameter.CreateAll(new Passphrase[] { identity.Passphrase }, identity.PrivateKeys, Resolve.CryptoFactory.OrderedIds); return(decryptionParameters); }