[erlang-questions] Pkcs padding

Max Lapshin max.lapshin@REDACTED
Mon Feb 26 14:03:07 CET 2018


Hi.

I was writing to ask for help, but found the solution myself,

Google widevine (DRM system) (
https://storage.googleapis.com/wvdocs/Widevine_DRM_Encryption_API.pdf
) requires signing JSON request.


Have spent half a day on "bad argument" from crypto library, but found that
I was not making padding for crypto.


The C++ code has:

Crypt(base::SHA1HashString(message), signature)

where Crypt has following:

    AES_cbc_encrypt(plaintext, ciphertext, cbc_size, aes_key(),
                    internal_iv_.data(), AES_ENCRYPT);


https://github.com/google/shaka-packager/blob/master/packager/media/base/aes_encryptor.cc#L61


I could make it work with such code:

Pkcs = fun(A,N) -> Pad = N - (size(A) rem N), <<A/binary,
(binary:copy(<<Pad>>, Pad))/binary>> end,
base64:encode(crypto:block_encrypt(aes_cbc256,AESKey,IV,Pkcs(JsonRequest,16))).


The trick is to add standard padding that makes content proper size.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180226/589e36ba/attachment.htm>


More information about the erlang-questions mailing list