Public/private key encoding standards exist to make this easier for
ourselves. You probably want to check out this link for a background on
public key encoding:

http://en.wikipedia.org/wiki/X.509

If you pay particular attention to the section on common certificate
file extensions you may notice a few acronyms that crop up in both
OpenSSL and Crypto++.

>From memory, I believe the keys I have generated are in X509, DER
encoding - these [public] keys can be viewed simply in a text editor
(like base64) because they are also HexEncoded:

<snip>
AutoSeededRandomPool seed; // Use the OS PRNG
RandomNumberGenerator *rng = &seed; // ASRP Base class

RSAES_OAEP_SHA_Decryptor decryptor (*rng, p_bits); // Create the RSA private 
key with a p_bits sized modulus
RSAES_OAEP_SHA_Encryptor encryptor (decryptor);  // Create the RSA public key 
from the private key

HexEncoder private_key (new FileSink (p_pv_file_name.c_str ())); // Encode the 
key as hexadecimal and save it to a file
decryptor.DEREncode (private_key); // PKCS8, DER encoded within the Hex 
encoding!
private_key.MessageEnd ();

string s;
HexEncoder public_key (new StringSink (s)); // Encode the key as hexadecimal 
and store it as a string

encryptor.DEREncode (public_key); // X509, DER encoded within the Hex encoding!
public_key.MessageEnd ();
</snip>

I hope this helps - it does leave a little for you to figure out for
yourself though ;)

Regards,

Jim Vanns

On Fri, 2005-12-30 at 12:00 -0500, Michael H. Pryor wrote:
> I've been using a private/public key pair for awhile now and I'd like to see
> if I can get them to work in PHP (using OpenSSL).  The keys I have are in
> binary format, with no header info in them.
> 
> For Crypto++ I would use the key to verify a sig like so (key data is in
> pbData)
> 
> StringSource keysPub((byte*)pbData, pubkeysize, true);
> RSASSA_PKCS1v15_MD5_Verifier rsaPub(keysPub);
> if (rsaPub.VerifyMessage((byte*)Z_STRVAL(slic), Z_STRLEN(slic), pbrevsig,
> Z_STRLEN(ssig)))
> 
> I would sign the data like so:
> 
>       StringSource keys((byte*)pbData, dwSize, true);
>       RSASSA_PKCS1v15_MD5_Signer rsaPriv(keys);
>       int iLen = rsaPriv.SignatureLength();
>       byte* out = new byte[iLen];
>       unsigned int signatureLength = rsaPriv.SignMessage(GlobalRNG(),
> (byte *)pStr, strlen(pStr), out);
> 
> Is there a way to take these binary keys and convert them to a base64 format
> (or whatever format) that openssl would recognize?
> 
> Thanks!
> 
> Michael 
> 
-- 
James Vanns BSc (Hons) MCP
Canterbury Christ Church University
Senior Systems Programmer (Linux / C & C++)
Encryption Key: 
http://keys.se.linux.org/pks/lookup?op=get&search=0x3B09EE224A653EA9
Signature Verification Key: 
http://keys.se.linux.org/pks/lookup?op=get&search=0x47FF170724959054


Reply via email to