I will turn Kuba's comment into an answer. The EncryptedObject
you create using Encrypt
contains the encrypted data and the initialization vector of the encryption method as a ByteArray
. These can be turned into an array of digits using Normal
and IntegerDigits
.
key = GenerateSymmetricKey[];
message = "Hello world";
eobj = Encrypt[key, message];
bin = eobj["Data"] // Normal // IntegerDigits[#, 2, 8] & // Flatten;
initvec =
eobj["InitializationVector"] // Normal // IntegerDigits[#, 2, 8] & // Flatten;
Now you send bin
and initvec
to the receiver (or do what ever else you wanted to do with the binary digits). To decrypt the message you can create a new EncryptedObject
and decrypt it:
eobj2 = EncryptedObject[Association[
"Data" -> ByteArray[(FromDigits[#1, 2] & ) /@ ArrayReshape[bin, {16, 8}]],
"InitializationVector" -> ByteArray[(FromDigits[#1, 2] & ) /@
ArrayReshape[initvec, {16, 8}]],
"OriginalForm" -> String]];
Decrypt[key, eobj2]
Note that I used ByteArray
, FromDigits
, and ArrayReshape
to reverse Kuba's Normal
, IntegerDigits
and Flatten
, respectively.
Encrypt[key, message]["Data"] // Normal // IntegerDigits[#, 2, 8] & // Flatten
$\endgroup$Decrypt[]
function is also expecting an encrypted object, not a sequence of binary digits. $\endgroup$