public void EnsureBackwardsCompatibilityLongTimeDecryptionOfTwofishGcm() { // Ensure that a once stored cipher can always be decrypted even after changes in the liberary string base64Cipher = "dW5pdHRlc3QkdHdvZmlzaF9nY20kZHhMWFh4K0UrZ2MzWHdWc01rWUFxQT09JHBia2RmMiRma1BCWTdDWXp1OG5YUlJtYk9DUlp3PT0kMTAwMCRRc0ETSqDekQuBgKJ5x4Mvy02OHsivm0uJ9KchKdpGk+pmbF4Kq/EDbx9Uw54uEZUQLnK70dNKSEVtb1GyUOX1mitr"; byte[] cipher = CryptoUtils.Base64StringToBytes(base64Cipher); ICryptor decryptor = new Cryptor("unittest", null); string decryptedMessage = CryptoUtils.BytesToString(decryptor.Decrypt(cipher, CryptoUtils.StringToSecureString("brownie"))); Assert.AreEqual("The brown fox jumps over the lazy 🐢🖐🏿 doc.", decryptedMessage); }
public void EnsureBackwardsCompatibilityLongTimeDecryptionOfAesGcm() { // Ensure that a once stored cipher can always be decrypted even after changes in the liberary string base64Cipher = "dW5pdHRlc3QkYWVzX2djbSQ0NG04QXBFU1ptcXhnYll2OE5wcWl3PT0kcGJrZGYyJGgwSDdxSGZnVFlXNzBKS3lEb0JLeFE9PSQxMDAwJJsMDjdYEYXYmcqTOFRbge6iVfWo/iny4nrIOMVuoqYak6xB/MAe53G5H3AyxiTi8OENJbi9tzZStpe3p3nlDB7l+J8="; byte[] cipher = CryptoUtils.Base64StringToBytes(base64Cipher); ICryptor decryptor = new Cryptor("unittest", null); string decryptedMessage = CryptoUtils.BytesToString(decryptor.Decrypt(cipher, CryptoUtils.StringToSecureString("brownie"))); Assert.AreEqual("The brown fox jumps over the lazy 🐢🖐🏿 doc.", decryptedMessage); }
public void EnsureBackwardsCompatibilityLongTimeDecryptionOfXChaCha() { // Ensure that a once stored cipher can always be decrypted even after changes in the liberary string base64Cipher = "dW5pdHRlc3Qgdj0yJHhjaGFjaGEyMF9wb2x5MTMwNSRsT0FJVW5wZXEyL0g3Ti96UkdCSktqaW9MdmFTUWk5eCRwYmtkZjIkdmN0dmpXVmx1NEhGbGhqbTV0SGlWQT09JDEwMDAwJCTcCqQglE3Xmfe0lg9AOhzxJXOuj7wEj+kgaSnKlZgnMyQwpQCwa9W57jnz1RhrwUuLh0X3PJpPbf7lR07Le7TFRZc8"; byte[] cipher = CryptoUtils.Base64StringToBytes(base64Cipher); ICryptor decryptor = new Cryptor("unittest", null); string decryptedMessage = CryptoUtils.BytesToString(decryptor.Decrypt(cipher, CryptoUtils.StringToSecureString("brownie"))); Assert.AreEqual("The brown fox jumps over the lazy 🐢🖐🏿 doc.", decryptedMessage); }
/// <summary> /// Decrypts the note, if the belonging safe is open. /// </summary> /// <returns>Decrypted note content, or null if the safe is closed.</returns> private string UnlockIfSafeOpen(string lockedContent) { SafeModel safe = _safes.FindById(Model.SafeId); if ((safe != null) && safe.IsOpen) { byte[] binaryContent = CryptoUtils.Base64StringToBytes(lockedContent); byte[] unlockedContent = _cryptor.Decrypt(binaryContent, safe.Key); return(CryptoUtils.BytesToString(unlockedContent)); } return(null); }
private void TestSymmetricEncryptionWithShortMessage(ISymmetricEncryptionAlgorithm encryptor) { ICryptoRandomService randomGenerator = CommonMocksAndStubs.CryptoRandomService(); byte[] key = randomGenerator.GetRandomBytes(encryptor.ExpectedKeySize); byte[] nonce = randomGenerator.GetRandomBytes(encryptor.ExpectedNonceSize); string message = "Dies ist ein kurzer Text"; byte[] binaryMessage = CryptoUtils.StringToBytes(message); byte[] cipher = encryptor.Encrypt(binaryMessage, key, nonce); Assert.AreNotEqual(binaryMessage, cipher); string message2 = CryptoUtils.BytesToString(encryptor.Decrypt(cipher, key, nonce)); Assert.AreEqual(message, message2); }
public void EnsureCompatibilityToLibsodiumXChaCha20() { // Ensure that a once stored cipher can always be decrypted even after changes in the liberary. // This cypher was created with libsodium. string base64Cipher = "q8w/Zotsi3ZJp2eaAnFmMiAGgko+N2TkNgunS5+bDRNqrBBoN+XMQPSt7ojO4ODMP3Rf3aoYMNeJFL2/ZqK3AngIuQ=="; byte[] cipher = CryptoUtils.Base64StringToBytes(base64Cipher); ISymmetricEncryptionAlgorithm decryptor = new BouncyCastleXChaCha20(); ICryptoRandomService randomGenerator = CommonMocksAndStubs.CryptoRandomService(88); byte[] key = randomGenerator.GetRandomBytes(decryptor.ExpectedKeySize); byte[] nonce = randomGenerator.GetRandomBytes(decryptor.ExpectedNonceSize); string decryptedMessage = CryptoUtils.BytesToString(decryptor.Decrypt(cipher, key, nonce)); Assert.AreEqual("The brown fox jumps over the lazy 🐢🖐🏿 doc.", decryptedMessage); }