Pkcs padding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Pkcs padding

Max Lapshin-2
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);




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.



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions