4
$\begingroup$

Decrypt[] will yield an error if one tries to decrypt a byte array using a different symmetric key than the one used to encrypt:

Decrypt[key2, Encrypt[key1, "foobar"]["Data"]]
> [..] Decrypt: Data could not be decrypted
> $Failed

I want to be able to mathematically perform the decrypt operation on a byte array and get a byte array even if the key doesn't match, for example, in 3DES. How can I force Decrypt to not yield a message and return the "decrypted" bytes? How does it even know that the decryption is correct or not with no knowledge of the plaintext bytes?

$\endgroup$
1
$\begingroup$

From the documentation:

Encrypt[key,"string"] yields an EncryptedObject containing the encrypted version of the contents of the string as encoded in UTF-8.

So the decrypted string must be valid UTF-8. However:

Encrypt[key,ByteArray[...]] yields an EncryptedObject containing the encrypted version of the raw bytes in the ByteArray object.

so if the encrypted thing is a ByteArray, it may work.

$\endgroup$
2
  • $\begingroup$ Nope, if you pass a ByteArray output from Encrypt[] it still fails: cryptMethod = <|"Cipher" -> "DES", "BlockMode" -> "ECB", "InitializationVector" -> None|>; Decrypt[GenerateSymmetricKey[Method -> cryptMethod], ByteArray[{77, 232, 217, 172, 56, 169, 190, 202}]] $\endgroup$
    – Sixty
    Nov 23 '18 at 16:24
  • $\begingroup$ Anyone know how to make this work? I see the same thing that the ByteArray passing doesn't change that it still "fails". There must be a checksum or something in addition to the encrypted data that is failing on the decryption. $\endgroup$
    – Mark R
    Jul 21 '19 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.