<div class="gmail_quote">On Tue, Apr 26, 2011 at 12:05 AM, Peter W. Morreale <span dir="ltr"><<a href="mailto:pmorreale@novell.com">pmorreale@novell.com</a>></span> wrote:<br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div class="h5">> I'm having a very difficult time getting the following to<br>> work:<br>> Cert2 = "-----BEGIN CERTIFICATE-----\nMIIB8TCCAVqgAwIBAgIFAIxwZnIwDQYJKoZIhvcNAQEEBQAwLjELMAkGA1UEBhMCREUxEjAQBgNVBAoTCVNTT0NpcmNsZTELMAkGA1UEAxMCQ0EwHhcNMDkwMjIyMTUwNDI0WhcNMTEwNTIyMTUwNDI0WjBLMQswCQYDVQQGEwJERTESMBAGA1UEChMJU1NPQ2lyY2xlMQwwCgYDVQQLEwNpZHAxGjAYBgNVBAMTEWlkcC5zc29jaXJjbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbzDRkudC/aC2gMqRVVaLdPJJEwpFB4o71fR5bnNd2ocnnNzJ/W9CoCargzKx+EJ4Nm3vWmX/IZRCFvrvy9C78fP1cmt6Sa091K9luaMAyWn7oC8h/YBXH7rB42tdvWLY4Kl9VJy6UCclvasyrfKx+SR4KU6zCsM622Kvp5wW67QIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAGyaydfJHDkm77C39gq9bBb7OqK8OXEUTbIMp8PDJZzIf9QkpkE7gHGcWctRKi7fNdONulc5kn2K2nbvCGrbWsWQvr/DA0bjkBrK8OeWpRhLe7fl+JUgsErMcDIzRTmjNpZzUZp+WESRHV1j3SIcfY4tJM2uMt4Sc/afVnl5P6wL\n-----END CERTIFICATE-----",<br>
><br>> Text = "some text",<br>><br>> Pb = list_to_binary(Cert2),<br>> PemEntries = public_key:pem_decode(Pb),<br>> RSAPubKey = public_key:pem_entry_decode(hd(PemEntries)),<br>
><br>> Msg = list_to_binary(Text),<br>> C = public_key:sign(Msg, sha, RSAPubKey),<br>> io:fwrite("sign: ~p~n", [C]),<br>><br>> I'm generating "escript: exception error: function_clause".<br>
</div></div></blockquote></div><div><br></div><div>First of all, the documentation of public_key:sign/3 found at <a href="http://www.erlang.org/doc/man/public_key.html#sign-3">http://www.erlang.org/doc/man/public_key.html#sign-3</a> is wrong. You should always sign with a private key so that every holder of your public key can verify the signature. The source code of public_key is correct though. There the type for signing is private_key().</div>
<div><br></div><div>Secondly, your variable RSAPubKey is a 'Certificate' record containing the public key data. The public_key:sign/3 function requires a 'RSAPrivateKey' or a 'DSAPrivateKey' record as its third argument. This is why you get your function_clause error.</div>
<div><br></div>-- <br>Jesper Pettersson<br>Klarna AB<br><br>