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

AW: [iaik-jce]



Hello,

please uncomment the lines

//ASN1Object obj1 = DerCoder.decode(encoding);
 //EncryptedContentInfo eci = new EncryptedContentInfo(obj1);

again. EncryptedContentInfo sets the cipher mode via constructor. When
creating a new EncryptedContentInfo for encrypting some data the mode is set
to ENCRYPT_MODE. When parsing an already existing EncryptedContentInfo
(given as encoding or ASN.1 object) the cipher mode is set to DECRYPT_MODE.
When commenting lines above you will encrypt twice.

An sample of EnvelopedDataStream is given in demo.pkcs.PKCS7Stream
(demo.pkcs.TestContentInfo).

Dieter Bratko

-----Ursprüngliche Nachricht-----
Von: iaik-jce-owner@iaik.tu-graz.ac.at
[mailto:iaik-jce-owner@iaik.tu-graz.ac.at]Im Auftrag von ravi
Gesendet: Montag, 18. September 2000 07:33
An: 'iaik-jce@iaik.at'
Betreff: [iaik-jce]


Hello,
I am tring this example given in documentation. But still not able to
retrieve my original string "Hai"?
Any help? Is it a bug? I am actually tring to use it in EnvelopedDataStream.
Any body can provide a working example of
EnvelopedDataStream??
Thanks


public class EnvData
{
public static void main(String[] args) throws Exception {
IAIK.addAsProvider(true);
//create a EncryptedContentInfo for the data to be encrypted, supplied as
byte array:
 byte[] data= "Hai".getBytes();
 EncryptedContentInfo eci = new EncryptedContentInfo(ObjectID.pkcs7_data,
data);
 //generate secret key and set up the cipher for encryption:
 javax.crypto.SecretKey key = eci.setupCipher(AlgorithmID.des_EDE3_CBC);
 //optionally set the block size for splitting the encoding:
 eci.setBlockSize(1024);
 //transform the EncryptedContentInfo into an ASN1Object or immediately
 //perform the DER encoding:
 ASN1Object obj = eci.toASN1Object(); //respectively:
 byte[]encoding = eci.getEncoded();
//create an EncryptedContentInfo from the given EncryptedContentInfo
ASN1Object:
 //(if the EncryptedContentInfo is supplied as DER encoding first decode it
to an ASN1Objet)
 //ASN1Object obj1 = DerCoder.decode(encoding);
 //EncryptedContentInfo eci = new EncryptedContentInfo(obj1);
 //setup the cipher with the right secret key and decrypt the encrypted
content:
 eci.setupCipher(key);
 //get the recovered raw data:
 byte[] data1 = eci.getContent();
 String str = new String(data1);
System.out.println(str);
}}

///////////////////////////////////////////////////
Ravi Sankar Veerubhotla
Research Fellow, IDRBT,
Castle Hills, Road No. 1
Masab Tank,
Hyderabad, (A.P.) 500 057.
INDIA.
Ph: +91-40-3534981 to 84 Ext. 2151
Fax: +91-40-3535157
Email: ravi@idrbt.ernet.in
///////////////////////////////////////////////////////

--
Mailinglist-archive at
http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content:
UNSUBSCRIBE iaik-jce




smime.p7s