RSA and hex string conversion
Zuxy Meng
zuxy.meng at gmail.com
Fri Feb 11 22:15:08 EST 2011
Hello,
I'm writing a protocol plugin for pidgin that deals with the following
tasks:
During account login, the server would return an RSA pubkey as its modulus
and exponent expressed in hex string like
"ccba8a2950e74226...."
And the client needs to encrypt with this key the SHA-1 hash of a string
that contains account name, password and random salt, and return the
encrypted message to the server.
With OpenSSL these tasks can be easily accomplished with functions like
BN_hex2bn(), RSA_public_encrypt(), SHA1_Update() etc., however, I don't want
to introduce a new dependency to my plugin and hope to use functions in
libpurple itself.
The SHA-1 hash can be beautifully accomplished with
purple_cipher_context_digest_to_str(), but libpurple doesn't support RSA
natively, so I have to turn to the NSS library that is shipped with
libpurple. Sadly the NSS interface to RSA encryption looks so tedious to me,
as I have to convert the hex string to DER format first and call lots of
supporting routines before the actual encryption.
Here I have two questions:
1. Is there any existing code in one of purple plugins that use NSS to do
RSA encryption?
2. Are there any existing functions in glib, gtk, purple or some other
library that purple depends on that can do a hex string -> byte array
conversion? I.e. convert the string "ccba8a29..." to { 0xcc, 0xba, 0x8a,
0x29, ... }
--
Zuxy
More information about the Devel
mailing list