[erlang-questions] Crypto Library Truncates the last bytes of ciphertext
Shobhit Singh
shobhitpratap1@REDACTED
Fri Jun 23 11:14:59 CEST 2017
Hi All,
I am facing a problem with encrypting AES 256 bit CBC in Erlang and then
decrypting it in c code. Whereas Encryption/decryption works in Erlang and
C but not from one to another.
the same data I Encrypted and decrypted in C and then made a Hex dump. The
actual Encrypted data Erlang is senginh is 128 Bytes and the same data
Encrypted by C openssl library is 144 bytes. That's normal cipher text are
usually long. Here's the output
This is send by Erlang
Encrypted = 128
a5 ab d0 68 18 61 ad 82 b1 63 32 16 33 b4 70 7b 24 12 d0 aa fa 83 c3
a2 b6 a2 fd 0e 79 f2 3d 3c
ca ac 4a 79 df 32 80 ff 86 33 fd 5b c3 ae 5a 5d 4d 41 01 73 77 40 19
83 2f f5 44 9c a3 91 6f 7d 8f d0 ff 35 83 dc ae f3 40 78 e5 15 56 6b
8b 94
a4 27 90 6a e8 40 fc ea 1a d0 8a bb d5 f4 d2 0b
ae 2f 7e 04 61 b3 c2 55 08 cf 74 8c ec 03 91 d15f 6a 24 79 f1 e4 99 78
e2 7d e3 8a 82 b7 d9 27
This is Output of Openssl (c) library fof the same data.
Encrypted = 144
a5 ab d0 68 18 61 ad 82 b1 63 32 16 33 b4 70 7b 24 12 d0 aa fa 83 c3
a2 b6 a2 fd 0e 79 f2 3d 3c
ca ac 4a 79 df 32 80 ff 86 33 fd 5b c3 ae 5a 5d 4d 41 01 73 77 40 19
83 2f f5 44 9c a3 91 6f 7d 8f d0 ff 35 83 dc ae f3 40 78 e5 15 56 6b
8b 94
a4 27 90 6a e8 40 fc ea 1a d0 8a bb d5 f4 d2 0b
ae 2f 7e 04 61 b3 c2 55 08 cf 74 8c ec 03 91 d1 5f 6a 24 79 f1 e4 99
78 e2 7d e3 8a 82 b7 d9 27
f7 01 c0 ed 95 e3 14 e5 d2 62 21 da a9 1d 2a e7
The last 16 bytes are missing from Erlang. Is there any other API I need to
call from Erlang Crypto library.
Erlang Code:
Ivec = "1200000000000000",Key =
"586E36EEE726B37F70A6F7B770764E99",Data =
"encrypt[38ce517c95b011bbfc999f36d09e4feb92d22dd8,38ce517c95b011bbfc999f36d09e4feb92d22222]",PaddedText
= string:left(Data ++ ",",128,$0),%%Data is
"encrypt[38ce517c95b011bbfc999f36d09e4feb92d22dd8,38ce517c95b011bbfc999f36d09e4feb92d22222],0000000000000000000000000000000000000"EncryptedText
= crypto:block_encrypt(aes_cbc256, Key, Ivec, PaddedText),%%Send to C
code
Thanks,
Shobhit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170623/469bb140/attachment.htm>
More information about the erlang-questions
mailing list