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

[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