[erlang-questions] How to encode data with private key?

Martin Koroudjiev mrtndimitrov@REDACTED
Tue Jun 14 14:17:03 CEST 2016


Hello,

I am trying to implement the OAuth 2 Google web service 2-legged flow.
When creating the service, I was granted a private key that I have to
use to sign the request. I try the following:

PrivKey = "-----BEGIN RSA PRIVATE KEY----- ...",
[PrivEntry] = public_key:pem_decode(list_to_binary(PrivKey)),
Priv = public_key:pem_entry_decode(PrivEntry),
public_key:encrypt_private(Data, Priv).

But I get the following error:

** exception error: no function clause matching
public_key:encrypt_private(<<"..".>>,
                                                                          
<<48,130,4,...>>,
                                                                          
[]) (public_key.erl, line 364)
     in function  jwt:encode/4 (../src/jwt.erl, line 25)

Does anyone know what the format of the Key must be for
public_key:encrypt_private(PlainText, Key)?

Thank you,
Martin




More information about the erlang-questions mailing list