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

Re: [iaik-jce]



For DES CBC the IV has to be encoded as OCTET_STRING:

algID.setParameter(new OCTET_STRING(iv));

Note, that

    EnvelopedDataStream enveloped_data = new EnvelopedDataStream(is, algID);

automatically will create a symmetric key for content encryption and setup
the cipher. For algorithms that require a particular key/parameter handling
the

 EnvelopedDataStream(RecipientInfo[], EncryptedContentInfoStream)

constructor shall be used to be supplied with precomputed RecipientInfos and
EncryptedContentInfo, e.g.:

EncryptedContentInfoStream eci =
          new EncryptedContentInfoStream(ObjectID.pkcs7_data, inputStream);
// parameters, key, algorithmID
AlgorithmParameters params = ...;
Key key = ...;
AlgorithmID algID = ...;
// set parameters for algID:
algID.setAlgorithmParameters(params);
// setup the cipher with algID, key and parameters:
eci.setupCipher(algID, key, params.getParameterSpec(paramSpec.class));
....
EnvelopedDataStream evd = new EnvelopedDataStream(recipientInfos, eci);
...

In similiar way, on recipient side the EncryptedContentInfo has to be
obtained from the EnvelopedData to explicitly parse the parameters and setup
the cipher for decryption:

//get the ECI from the enveloped data:
 EncryptedContentInfoStream eci =
      (EncryptedContentInfoStream)enveloped_data.getEncryptedContentInfo();
 // get the content encryption algorithm:
 AlgorithmID contentEA = eci.getContentEncryptionAlgorithm();
 // get and parse the parameters:
 ASN1Object params =  contentEA.getParameter();
 // create an AlgorithmParameterSpec from the parameters to setup the cipher
for decryption with previously decrypted recipient key
 ...
 eci.setupCipher(secretKey, paramSpec);
 // get and read the data thereby actually performing the decryption
 InputStream data_is = eci.getInputStream();
 ....

See the Javadoc of 2.51 for an example.

Dieter Bratko




----- Original Message -----
From: Ingrassia Vito <ingrassi@cefriel.it>
To: <iaik-jce@iaik.tu-graz.ac.at>
Sent: Thursday, July 29, 1999 11:50 AM
Subject: [iaik-jce]


> Hello,
>
> I'm working with  iaik.pkcs.pkcs7.EnvelopedDataStream  class.
> I'm working with this code:
> (I have already setted RecipientInfo[]  for only a recipient)
>
>         AlgortihmID algID = Algortihm.des_CBC;
> Cipher c = (Cipher) algID.getInstance();
>             byte[] bytes = new byte[c.getBlockSize()];
>             java.util.Random random = new java.util.Random();
>             random.nextBytes(bytes);
>             String s = new String(bytes);
>
> GeneralString generalString = new GeneralString(s);
>             algID.setParameter(generalString);
>
> EnvelopedDataStream enveloped_data = new EnvelopedDataStream(is, algID);
>   enveloped_data.setRecipientInfos(recipients);
>
>   enveloped_data.writeTo(os );
>
> On recipient   side  I wrote: (os -----> is)
>
>   EnvelopedDataStream envelop_data = new EnvelopedDataStream(is);
> PrivateKey pk = ........(the rigth public key)
>             envelop_data.setupCipher(pk, 0);
>
> but  this exception throws:
>
> iaik.pkcs.PKCSException: Unable to get algorithm parameter!
>    at iaik.pkcs.pkcs7.EncryptedContentInfoStream.setupCipher(Unknown
Source)
>    at iaik.pkcs.pkcs7.EnvelopedDataStream.setupCipher(Unknown Source)
>    at
>
it.cefriel.cosmos.pse.PSEServerImpl.extractEnvelopedData(PSEServerImpl.java:
> 1916)
>    at
>
it.cefriel.cosmos.pse.PSEServerImpl_Skel.dispatch(PSEServerImpl_Skel.java:80
> 3)
>    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:164)
>    at sun.rmi.transport.Transport.serviceCall(Transport.java:161)
>    at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:593)
>    at sun.rmi.transport.tcp.TCPTransport.run(TCPTransport.java:499)
>    at java.lang.Thread.run(Thread.java:474)
>
> I think I have setted  algorithm parameters  in a bad way but
> I  don't find other solution.
> Suggested me  one., please
>
> Thank you,
>
> Vito
>
> --
> Mailinglist-archive at
http://jcewww.iaik.tu-graz.ac.at/mailarchive/iaik-jce/maillist.html
>
> To unsubscribe send an email to listserv@iaik.tu-graz.ac.at with the
folowing content: UNSUBSCRIBE iaik-jce
>
>
>


smime.p7s