[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iaik-jce] DER encoding an RSAPublicKey



The documentation is inaccurate, the encoding returned by getEncoded() is a
DER encoded PublicKeyInfo. A "raw" option is not available because it is
never used in practice. If you need it you could either extend the
RSAPublicKey class and use the protected encode() method (I cannot really
recommend that) or build it yourself as you wrote in your email.

Regards,

 Andreas Sterbenz              mailto:Andreas.Sterbenz@iaik.at


> ----- Original Message -----
> From: "Mauro Marini" <mmarini@intesigroup.com>
> To: <iaik-jce@iaik.tu-graz.ac.at>
> Sent: Wednesday, December 20, 2000 2:45 PM
> Subject: [iaik-jce] DER encoding an RSAPublicKey
>
>
> iaik.security.rsa.RSAPublicKey documentation claims:
>
> ---------
> PKCS#1 describes a X.509/PEM compatible syntax for RSA public keys to be
> used in certificates. The corresponding ASN.1 type RSAPublicKey is defined
> as ASN.1 SEQUENCE:
>  RSAPublicKey ::= SEQUENCE {
>    modulus INTEGER, -- n
>    publicExponent INTEGER -- e }
> ---------
>
> Well, if I  use this code:
> iaik.security.rsa.RSAPublicKey PubKey1 =
>     new iaik.security.rsa.RSAPublicKey (Modulus, Exponent);
> ASN1Object asn1object = PubKey1.toASN1Object();
> System.err.write( ASN1.print(asn1object).getBytes());
>
> I get:
>
> SEQUENCE[C] = 2 elements
>   SEQUENCE[C] = 2 elements
>     OBJECT ID = rsaEncryption
>     NULL = null
>   BIT STRING = 139 byte(s); 0 bit(s) not valid
>
> But this is the DER encoding of the superclass iaik.x509.PublicKeyInfo !
> I tried in different ways but that's the result I always get.
> OK, I can build the correct SEQUENCE  (INTEGER INTEGER)
> by myself, but is this a wanted behaviour or am I doing something wrong?
> Is there another straight way to encode an RSAPublicKey?



smime.p7s