public string Decrypt(string decryptStr) { if (string.IsNullOrEmpty(_original)) { throw new System.NullReferenceException("can't found the original value.."); } else { string pcbcDecrypted = XOR.Gate(_original, _pcbcEncrypted); return(_baseCbc.Decrypt(pcbcDecrypted)); } }
public void Decrypt_DecryptsBlock_Decrypted() { byte[] bytes = { 0xdb, 0xf1, 0x84, 0x11, 0x2e, 0xb9, 0x11, 0x16, 0x59, 0x71, 0x2b, 0xaf, 0xcf, 0xf2, 0xab, 0x24, 0x28, 0xa7, 0x63, 0x6c, 0x8e, 0x91, 0x91, 0xcb, 0x11, 0x39, 0x72, 0x2e, 0xb7, 0xa6, 0x4c, 0x2e }; byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; var encryptor = new CBC(new AES(key), new PKCS7Padding(), key); var input = new MemoryStream(bytes); var output = new MemoryStream(); encryptor.Decrypt(input, output); byte[] result = output.GetBuffer().SubArray(0, 16); CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, result); }
public void Decrypt_Decrypts10Bytes_Decrypted() { byte[] bytes = { 0xff, 0x07, 0x90, 0x16, 0xe7, 0x8a, 0x17, 0xa4, 0xb5, 0xce, 0x2e, 0xac, 0x2b, 0x00, 0xe8, 0x48 }; byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; var encryptor = new CBC(new AES(key), new PKCS7Padding(), key); var input = new MemoryStream(bytes); var output = new MemoryStream(); encryptor.Decrypt(input, output); byte[] result = output.GetBuffer().SubArray(0, 10); CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, result); }