View Source WhatsappFlowCrypto (WhatsApp-Flow-Crypto v0.1.0)
Load the private key from the file system. The private key is reused once loaded. The library returns a reference
to the private key. This can be done by the function fetch_private_key/2
. Just read the private key and
call the function to receive a reference of the private key. If the private key is encrypted you need to
specify the password.
For each request, we do the encryption like this:
- Decrypt the encrypted AES key
- Decrypt the request with initial vector and the encrypted AES key
- Encrypt the response with the inverted initial vector and the encrypted AES key
{:ok, private_key_pem} = File.read(private_pem_path);
WhatsappFlowCrypto.fetch_private_key(private_key_pem, "test")
{:ok, #Reference<0.1652491651.443678740.227250>}
After this, you can decrypt the request. The request contains
- the encrypted AES key
- the initial vector
- the encrypted flow data
All values are base64 encoded.
WhatsappFlowCrypto.decrypt_request(private_key_ref, encrypted_aes_key, initial_vector, encrypted_flow_data)
{:ok, {decrypted_body, aes_key, initial_vector}}
WhatsappFlowCrypto.encrypt_response(aes_key, initial_vector, response)
"KUkRnUDAUKqhiovnQ9RRwmdBjcg87/wh+ZrMtbh8xlx3"
Summary
Functions
Decrypts the encrypted body and AES key using the private key reference. It returns the decrypted JSON map, the decrypted AES key and the initial vector. They are need to decrypt the response.
Encrypts the response using the decrypted_aes_key and initial vector of the request. The response will be encoded as JSON.
Fetches the private key from the pem. The password is optional and only needed if the private key is encrypted. Heads up: some cipher are not supported by this library. The DES3 cipher is unsupported. You can use another cipher (AES-128) to encrypt the private key.
Functions
decrypt_request(private_key_ref, encrypted_aes_key, initial_vector, encrypted_flow_data)
View SourceDecrypts the encrypted body and AES key using the private key reference. It returns the decrypted JSON map, the decrypted AES key and the initial vector. They are need to decrypt the response.
Encrypts the response using the decrypted_aes_key and initial vector of the request. The response will be encoded as JSON.
Fetches the private key from the pem. The password is optional and only needed if the private key is encrypted. Heads up: some cipher are not supported by this library. The DES3 cipher is unsupported. You can use another cipher (AES-128) to encrypt the private key.