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

Re: [iaik-jce] CAST5



Hello,
Are you sure you have encrypted the secrect content encryption key for each
participated recipient?, e.g:

for (int i = 0; i < recipients.length; i++) {
   recipients[i].encryptKey(secretKey);
 }

Dieter Bratko

----- Original Message -----
From: Vito Ingrassia <ingrassi@cefriel.it>
To: IAIK <iaik-jce@iaik.tu-graz.ac.at>
Sent: Tuesday, August 24, 1999 5:16 PM
Subject: [iaik-jce] CAST5


> Hello,
> I'm trying to use EnvelopedDataStream with CAST128 and RC2 ciphers.
> As was suggested to me I wrote in my code
>
> // the data input stream
> InputStream is = ...;
> // create a secretKey with desired key length:
> int keyLength = ...;
> SecretKey secretKey = ...;
> // the content encryption AlgorithmID:
> // CAST5:
> AlgorithmID contentEA = AlgorithmID.cast5_CBC
> file://I use a cipher to get blocksize for iv
> Cipher c = (Cipher) contentEA.getInstance();
> byte[] iv = new byte[c.getBlockSize()];
> java.util.Random random = new java.util.Random();
> random.nextBytes(iv);
>
> file://AlgorithmParameterSpec
> IvParameterSpec params = new IvParameterSpec(iv);
>
> OCTET_STRING oct = new OCTET_STRING( bytes );
> contentEA.setParameter(oct);
> // now create EncryptedContentInfo:
> EncryptedContentInfoStream eci = new
> EncryptedContentInfoStream(ObjectID.pkcs7_data, is);
>
> // setup the cipher:
> eci.setupCipher(contentEA, secretKey, params);
>
> // create the recipient infos, e.g.:
> eci =  ..................
>
> // create the EnvelopedDataStream
> EnvelopedDataStream enveloped_data = new EnvelopedDataStream(recipients,
> eci);
> // write enveloped data
> enveloped_data.writeTo(os, blockSize);
>
>
> and in this writeTo  I catch  the following exception
>
> java.lang.NullPointerException
>         at iaik.utils.StreamCopier.copyStream(Unknown Source)
>         at iaik.asn1.OCTET_STRING.encode(Unknown Source)
>         at iaik.asn1.ASN1Object.encodeObject(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.ConstructedType.encode(Unknown Source)
>         at iaik.asn1.ASN1Object.encodeObject(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.ConstructedType.encode(Unknown Source)
>         at iaik.asn1.ASN1Object.encodeObject(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.DerCoder.a(Unknown Source)
>         at iaik.asn1.DerCoder.encode(Unknown Source)
>         at iaik.asn1.DerCoder.encodeTo(Unknown Source)
>         at iaik.asn1.ConstructedType.encode(Unknown Source)
>         at iaik.asn1.ASN1Object.encodeObject(Unknown Source)
>         at iaik.asn1.DerCoder.encodeTo(Unknown Source)
>         at iaik.asn1.DerCoder.encodeTo(Unknown Source)
>         at iaik.pkcs.pkcs7.EnvelopedDataStream.writeTo(Unknown Source)
>
............................................................................
.........
>
>
>
> I realize that this appens also for  RC2 (AlgorithmID.rc2_CBC);
>
> Another question is if this way it's possible also for
> algorithms having a fixed key length and using an IV as  only parameter
> as DES.
> In this case  the only way is the constructor
> EnvelopedDataStream enveloped_data = EnvelopedDataStream( is,
> algorithmID)?;
>
> 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