On Sun, Feb 22, 2009 at 02:48, Gary <[email protected]> wrote:
> I read  RFC5280 for subjectPublicKeyInfo  structure and found it as
> below:
>
>   SubjectPublicKeyInfo  ::=  SEQUENCE  {
>        algorithm            AlgorithmIdentifier,
>        subjectPublicKey     BIT STRING  }
>

That's the structure that's encoded to the file. It's used for many
different algorithms, not just RSA. The RSA-specific parts can be
found in RFC 3279, where they define the contents of the
subjectPublicKey field's BIT STRING.

>
> And PrivateKeyInfo as below:
>
> PrivateKeyInfo ::= SEQUENCE {
>  version Version,
>  privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
>  privateKey PrivateKey,
>  attributes [0] IMPLICIT Attributes OPTIONAL }
> Version ::= INTEGER
> PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
> PrivateKey ::= OCTET STRING
> Attributes ::= SET OF Attribute
>
> But I can't understand which part of public or private key is "n" and
> which part of private key is "d" and which part of public key is "e"
> yet!

Likewise, that's the structure that's encoded into the private key
file. As with the SubjectPublicKeyInfo structure, it too can be used
for different algorithms, not only RSA. The private key is in the
PrivateKey field of PrivateKeyInfo. That, for RSA is a RSAPrivateKey
structure as defined by PKCS#1. Look at PKCS#1's asn.1 module (on the
RSA site I linked earlier) to see the ordering of the fields.

>
> What I want, is that generate 128 bytes(Hex bytes) for n(modulus) and
> 128 bytes for d(private exponent)
> and store them into two byte array!

Look at the dump keys sample on the RSA wiki page Jeff linked for you.
When you retrieve the fields, instead of sending them to an ostream as
that sample does, let the CryptoPP::Integer objects encode themselves
into byte arrays:

http://www.cryptopp.com/docs/ref/class_integer.html

> One other request!
> Have you any successfully built sample codes of hashing data with SHA1
> algorithm?
> Sample codes in "Crypto++ user's guide" don't match with "CryptoPP
> 5.5.2" version and couldn't help me  at all ,so I need a sample code
> of hashing data with SHA1 algorithm which stores the digest in a byte
> array that will be compiled successfully such examples on this page:
>  http://www.cryptopp.com/wiki/RSA_Cryptography#Key_Encoding
>

Here's a trivial example calculates a SHA1 digest over a file, writes
that digest into a byte array, then hex encodes that byte array and
prints it to standard output. Use it for whatever you want, including
transer to the wiki :-)

http://cryptopp.pastebin.com/f4a986357

Good luck.

Geoff

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to