How to make one file?

I have basically 2 problems here
a)When I do generate a signature using the enduser's privatekey,,I will be ending up with two files one signature file and other the original document,,I need one file which contains the signature as well as the original doc in readable format and also i can authenticate doc using the same signature presemt in that file.
b)In PKI scenario shud i encrypt the doc(data) without signature or shud i encrypt the doc as well as the signature also?
c)If i have the signature as separate entity how can i find out publickey attributes or any information of the public key using the signature that is there?
Plz do repond asap with exaples if possible,
thnx in advnce
Subhash

Yup...I need one more help i.e I was able to encrypt/decrypt using assymtric and symetric,,the flow was like this...I had a key pair...
I generate a DES key then I create a cipher by the data string,,then i used to encrypt the des key and store it in the database...then again at the server i used to decrypt the symmetric key using the private key from the key pair and then descrypt the data...it was all well and fine..
now instaed of string i tried MSword of MSEXCELL i wasnt able to do at ll..some suggested to do padding so i tried des/cbc/pkcs5padding...it was encryting well but again i was stuck while decrypting,,it was asking for IV parametr and all,,i tried a lot but wasnt out of it...
now my question is shud i include the getIv byte even in the encrypted file also...???
i wud like to paste the code,,plz help me...
encryption part is
import java.io.*;
import java.security.*;
import java.security.spec.*;
import java.security.spec.X509EncodedKeySpec;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAKey;
import java.io.*;
import java.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.*;
import java.math.BigInteger;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.Key;
import java.security.KeyFactory;
import java.security.Security;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class FileEncrypt
byte[] encryptedDESKey;
// encryptPart variables
KeyGenerator kg;
Key key;
Cipher cipher;
RSAPublicKey rsaPublicKey;
Cipher encryptCipher;
// decryptedPart variables
RSAPrivateKey priv;
Cipher decryptCipher;
byte[] decryptedDESKey;
SecretKeyFactory skf;
DESKeySpec desKeySpec;
SecretKey sk;
Cipher desCipher;
public static void main(String args[]){
     String path = "C://USB//test.doc";
     String fileName = "C://USB//ENCtest.doc";
FileEncrypt pk1 = new FileEncrypt();
String encryptedPassword = pk1.encryptPart(path,fileName);
     Connection con = null;
Statement stmt = null;
ResultSet rs = null;
//XlEncrypt tt = new XlEncrypt();
TxtFile profile = new TxtFile();
try{
DriverManager.registerDriver (profile.getDriver());
con =DriverManager.getConnection (profile.getURLName(), profile.getUserName(), profile.getPassword());
stmt = con.createStatement();
con =DriverManager.getConnection (profile.getURLName(), profile.getUserName(), profile.getPassword());
stmt = con.createStatement();
stmt.executeUpdate("insert into test (pki) values('"+encryptedPassword+"')");
}catch (SQLException e) {
System.out.println (e.getMessage() + "Problem in getting connections");
private String encryptPart(String path,String fileName){   
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
try{
// create des key
kg = KeyGenerator.getInstance("DES");
key = kg.generateKey();
// encrypt some data
//cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE,key);
//read in cert from file and get public key and decrypt des key
rsaPublicKey = getRSAPublicKey("buyer");
encryptCipher= Cipher.getInstance("RSA","BC");
encryptCipher.init(Cipher.ENCRYPT_MODE,rsaPublicKey);
encryptedDESKey = encryptCipher.doFinal(key.getEncoded());
     FileEncrypt tt = new FileEncrypt();
String sd = tt.hexEncode(encryptedDESKey);
int c;
FileInputStream fis = new FileInputStream(path);
StringBuffer fileBuffer = new StringBuffer();
while((c=fis.read())!=-1){
fileBuffer.append((char)c);
String fileString = fileBuffer.toString();
byte[] encword = cipher.doFinal(fileString.getBytes());
String outFile = tt.hexEncode(encword);
DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
out2.writeBytes(outFile);
out2.close();
return sd;
}catch(Exception e)
System.out.println("<ERROR>\nIn encryptPart\n"+e.toString()+"\n</ERROR>");
return null;
/** This array is used to convert from bytes to hexadecimal numbers */
static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
* A convenience method to convert an array of bytes to a String. We do
* this simply by converting each byte to two hexadecimal digits. Something
* like Base 64 encoding is more compact, but harder to encode.
public static String hexEncode(byte[] bytes) {
StringBuffer s = new StringBuffer(bytes.length * 2);
for(int i = 0; i < bytes.length; i++) {
byte b = bytes;
s.append(digits[(b & 0xf0) >> 4]);
s.append(digits[b & 0x0f]);
return s.toString();
* A convenience method to convert in the other direction, from a string
* of hexadecimal digits to an array of bytes.
public static byte[] hexDecode(String s) throws IllegalArgumentException {
try {
int len = s.length();
byte[] r = new byte[len/2];
for(int i = 0; i < r.length; i++) {
int digit1 = s.charAt(i*2), digit2 = s.charAt(i*2 + 1);
if ((digit1 >= '0') && (digit1 <= '9')) digit1 -= '0';
else if ((digit1 >= 'a') && (digit1 <= 'f')) digit1 -= 'a' - 10;
if ((digit2 >= '0') && (digit2 <= '9')) digit2 -= '0';
else if ((digit2 >= 'a') && (digit2 <= 'f')) digit2 -= 'a' - 10;
r[i] = (byte)((digit1 << 4) + digit2);
return r;
catch (Exception e) {
throw new IllegalArgumentException("hexDecode(): invalid input");
// encryptPart private method
private RSAPublicKey getRSAPublicKey(String userName){
try{
FileInputStream fis = new FileInputStream("C:/certificates/buyer/buyer.crt");
BufferedInputStream bis = new BufferedInputStream(fis);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = null;
while(bis.available() > 0){
cert = (X509Certificate)cf.generateCertificate(bis);
return (RSAPublicKey)cert.getPublicKey();
catch(Exception e){
System.out.println("<ERROR>\nTrying to get Public Key from cert\n"+e.toString()+"\n</ERROR>");
return null;
decryption part is
import java.io.*;
import java.security.*;
import java.security.spec.*;
import java.security.spec.X509EncodedKeySpec;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAKey;
import java.io.*;
import java.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.*;
import java.math.BigInteger;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.Key;
import java.security.KeyFactory;
import java.security.Security;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class FileDecrypt
byte[] encryptedDESKey;
// encryptPart variables
KeyGenerator kg;
Key key;
Cipher cipher;
RSAPublicKey rsaPublicKey;
Cipher encryptCipher;
// decryptedPart variables
RSAPrivateKey priv;
Cipher decryptCipher;
byte[] decryptedDESKey;
SecretKeyFactory skf;
DESKeySpec desKeySpec;
SecretKey sk;
Cipher desCipher;
public static void main(String args[]){
     String inputFile = "C://Usb//ENCtest.doc";
     Connection con = null;
Statement stmt = null;
ResultSet rs = null;
     TxtFile profile = new TxtFile();
     String var="";
     try {
DriverManager.registerDriver (profile.getDriver());
con =DriverManager.getConnection (profile.getURLName(), profile.getUserName(), profile.getPassword());
stmt = con.createStatement();
con =DriverManager.getConnection (profile.getURLName(), profile.getUserName(), profile.getPassword());
stmt = con.createStatement();
rs = stmt.executeQuery("select pki from test");
if(rs.next()){
var = rs.getString("pki");
}catch (SQLException e) {
System.out.println (e.getMessage() + "Problem in getting connections");
     System.out.println(var);
     String encSymKey = var;
     FileDecrypt tpk = new FileDecrypt();
String decryptedPassword = tpk.decryptPart(inputFile,encSymKey);
//return decryptedPassword;     
private String decryptPart(String inputFile,String encSymKey)
try{   
// get private key from file
priv = getRSAPrivateKey();
// decrypted des key
int c;
Security.addProvider(new BouncyCastleProvider());
FileDecrypt t1 = new FileDecrypt();
byte[] encryptedDESKey1 = t1.hexDecode(encSymKey);
decryptCipher = Cipher.getInstance("RSA","BC");
decryptCipher.init(Cipher.DECRYPT_MODE,priv);
decryptedDESKey = decryptCipher.doFinal(encryptedDESKey1);
// convert bytes back to des key
skf = SecretKeyFactory.getInstance("DES");
desKeySpec = new DESKeySpec(decryptedDESKey);
sk = skf.generateSecret(desKeySpec);
// decrypt the encrypted password
//desCipher = desCipher.getInstance("DES/ECB/PKCS5Padding");
desCipher = desCipher.getInstance("DES");
               desCipher.init(Cipher.DECRYPT_MODE,sk);     
//desCipher.init(Cipher.DECRYPT_MODE,sk);
FileDecrypt obj1 = new FileDecrypt();
FileInputStream fis = new FileInputStream(inputFile);
StringBuffer encryptedFile = new StringBuffer();
while((c=fis.read())!=-1){
encryptedFile.append((char)c);
String encFile = encryptedFile.toString();
System.out.println(encFile);
byte[] jk =obj1.hexDecode(encFile);
String encVar = new String(desCipher.doFinal(jk));
//String encVar = new String(desCipher.doFinal(jk));
DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("C:/usb/dectest.doc")));
out2.writeBytes(encVar);
out2.close();
//System.out.println(new String(desCipher.doFinal(jk)));
return new String("subhash");
}catch(Exception e){
System.out.println("<ERROR>\nIn decryptPart\n"+e.toString()+"\n</ERROR>");
return null;
// decryptPart private method
private RSAPrivateKey getRSAPrivateKey()
try{
File keyFile = new File("C:/certificates/buyer/buyerkey.der");
DataInputStream in = new DataInputStream(new FileInputStream(keyFile));
byte [] fileBytes = new byte[(int) keyFile.length()];
in.readFully(fileBytes);
in.close();
KeyFactory kf = KeyFactory.getInstance("RSA");
KeySpec ks = new PKCS8EncodedKeySpec(fileBytes);
return (RSAPrivateKey)kf.generatePrivate(ks);
}catch(Exception e){
System.out.println("<ERROR>\nTrying to get Private Key from file\n"+e.toString()+"\n</ERROR>");
return null;
/** This array is used to convert from bytes to hexadecimal numbers */
static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
* A convenience method to convert an array of bytes to a String. We do
* this simply by converting each byte to two hexadecimal digits. Something
* like Base 64 encoding is more compact, but harder to encode.
public static String hexEncode(byte[] bytes) {
StringBuffer s = new StringBuffer(bytes.length * 2);
for(int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
s.append(digits[(b & 0xf0) >> 4]);
s.append(digits[b & 0x0f]);
return s.toString();
* A convenience method to convert in the other direction, from a string
* of hexadecimal digits to an array of bytes.
public static byte[] hexDecode(String s) throws IllegalArgumentException {
try {
int len = s.length();
byte[] r = new byte[len/2];
for(int i = 0; i < r.length; i++) {
int digit1 = s.charAt(i*2), digit2 = s.charAt(i*2 + 1);
if ((digit1 >= '0') && (digit1 <= '9')) digit1 -= '0';
else if ((digit1 >= 'a') && (digit1 <= 'f')) digit1 -= 'a' - 10;
if ((digit2 >= '0') && (digit2 <= '9')) digit2 -= '0';
else if ((digit2 >= 'a') && (digit2 <= 'f')) digit2 -= 'a' - 10;
r[i] = (byte)((digit1 << 4) + digit2);
return r;
}catch (Exception e) {
throw new IllegalArgumentException("hexDecode(): invalid input");
plz do reply asap,,
bye
Subhash

Similar Messages

  • How to make one file out of many documents?

    Hi, I have a collection of documents created in Pages. I would like to have these available as a single file. I currently have a workaround where I change each document to a PDF, then use Acrobat to create a single PDF from each individual PDF. However this is cumbersome and I would like to maintain the Pages file type.
    I am aware that I cannot insert one Pages document into another - but is there any way to automate or work around this other than copying and pasting each document into a new file?
    Thank you,
    G5   Mac OS X (10.4.6)  

    Hello bottlenose,
    when you are working with Pages 2.x than you can copy and paste the thumbnail pages out of and into the thumbnail views (menu: "View/Show Page Thumbnails") of multiple documents. The only thing you should know is, the inserted style names will be overwritten by the existing styles with the same name. So be sure you have different style names for different paragraph appearances in both documents before you copy them.
    By the way, the is a handy little app called "PDFLab" (grab it here: http://www.iconus.ch/fabien/pdflab/) with which you can combine and split PDF documents (and do a lot of other things) without starting the behemoth Acrobat.

  • How to make jar file for this compilation method ?

    can any one tell me how to make jar file for this compilation
    D:\java\browser\IEInJava>javac -classpath jdic.jar;. IEInJava.java
    D:\java\browser\IEInJava>java -cp jdic.jar;. IEInJava
    *this is a compile code:-*
    D:\java\browser\IEInJava>javac -classpath jdic.jar;. IEInJava.java
    *and this is a run code:-*
    D:\java\browser\IEInJava>java -cp jdic.jar;. IEInJavanow how make JAR file ?

    Assuming IEInJava only uses classes inside the jdic jar, this is one way. D:\java\browser\IEInJava> jar cf yourjar.jar IEInJava.classThen to run it you would use D:\java\browser\IEInJava> java -cp jdic.jar;yourjar.jar IEInJavaAnother way would use the jar manifest file to specify the Main-Class and Class-Path.

  • How to make one dvd from several camcoder dvd's

    How to make one dvd from several camcoder dvd's. I got a dvd camcoder, to be able to play them into DVD player I had to finalize  my disks. Now I got several DVD's whith short files and terrible custom camera menu. I'd like to make it more presentable.
    The main problem is I dont want to recode my vob files. So Final Cut and other editing soft is bad idea.
    Is there any soft on mac I could reauthor my DVD's?

    How to make one dvd from several camcoder dvd's. I got a dvd camcoder, to be able to play them into DVD player I had to finalize  my disks. Now I got several DVD's whith short files and terrible custom camera menu. I'd like to make it more presentable.
    The main problem is I dont want to recode my vob files. So Final Cut and other editing soft is bad idea.
    Is there any soft on mac I could reauthor my DVD's?

  • HT5796 I was on a a different Apple ID and I logged out because they didn't want me on there anymore so I figured out how to make one and now it's not letting me upgrade or download anything. I rebooted my iPhone 5, iOS 7.0.4 multiple times nothing fixed

    I was on a a different Apple ID and I logged out because they didn't want me on there anymore so I figured out how to make one and now it's not letting me upgrade or download anything. I rebooted my iPhone 5, iOS 7.0.4 multiple times nothing fixed my problem.

    I was on a a different Apple ID and I logged out because they didn't want me on there anymore so I figured out how to make one and now it's not letting me upgrade or download anything. I rebooted my iPhone 5, iOS 7.0.4 multiple times nothing fixed my problem.

  • How to make html file on server side from the data entered in text area

    Hi!
    I want to know how to make .html file on server side. Like if i enter the data in text area ( or like we normaly see when we write mail that editor) and we can use html tages in it and when user submit form all the data in that field will be saved on server side as an html formate. Is it possible to do so??? or any ruff idea how to design it???

    Erm ...
    Whats the problem with that?!
    Ok, here the code ...
    String myparameter = request.getParameter("paramname");
    String htmltemplate = "<html>\n"
                         +"<head><title>demo</title></head>\n";
                         +"<body>@parametertag@</body>\n";
                         +"<html>";
    String htmlpage = htmltemplate.replaceAll("@parametertag@",myparameter);
    File yourHTMLfile = new File("wheredoyouwannagotoday.html");
    FileOutputStream fos = new FileOutputStream(yourHTMLfile);
    fos.write(htmlpage.getBytes());
    fos.close();You're done.
    Happy Coding! :-) &copy;

  • How to make Jar files in JBuilder

    I would like to know how to make jar files using JBulider. I have a problem with a project that I am working with in Swing. I have made the project on JBuilder and when I make a jar file it will not run upon clicking.
    Any body with an answer, please help
    Abhi

    It sounds like your Main-Class is not set properly in your manifest. To set your Main-Class, please follow these directions:
    http://java.sun.com/docs/books/tutorial/jar/basics/run.html

  • How to make jar files availabe for deployed EJBs

    Hi,
    I'm interested on how to make jar files availabe for deployed EJBs.
    My EJB is packed in an ear. It uses a util jar. I now just add the jar to the
    classpath, but I think that shouldn't be the way. Is there somthing in the admin
    console to make jars available or do I have to insert it in the ear file? And
    if so, where do I hve to place it?
    Thanks
    Claudia

    Put the util.jar in the ear with your ejb jars - at the same level (i.e. in
    the root) - but do not include them in the manifest.xml.
    Also each ejb jar that refers to util.jar must have util.jar on its internal
    classpath in the manifest.
    "Claudia" <[email protected]> wrote in message
    news:3d537db5$[email protected]..
    >
    Hi,
    I'm interested on how to make jar files availabe for deployed EJBs.
    My EJB is packed in an ear. It uses a util jar. I now just add the jar tothe
    classpath, but I think that shouldn't be the way. Is there somthing in theadmin
    console to make jars available or do I have to insert it in the ear file?And
    if so, where do I hve to place it?
    Thanks
    Claudia

  • Slide duration - How to make one slide have a different duration to another slide?

    Slide duration - How to make one slide have a different duration to another slide?
    EG So one slide has 2 seconds, another 4 another 6
    All I can see is how to make all slides have the same duration
    Any help very much appreciated!
    Brian

    Slide durations are not changeable on a slide-by-slide basis.

  • How to make html file from a text field data

    hi!
    I want to know how to make a file with .html extension and the data in this file should be from a text field. like i want to enter some thing in a text area and have to place it in a file on server side in html formate.

    so you told us what you want, but what is your question?

  • How to make word files in mac

    how to make word files, presentations orview such files in mac

    Open Office can be opened in MS Word, and vice versa, looks nearly 100% same as Office and Word but is FREE
    tons use it
    http://www.openoffice.org/download/index.html

  • How to make pdf file auto open with adobe reader after downloaded

    how to make pdf file auto open with adobe reader after downloaded

    I note from your system details that you have the plugin for adobe pdf s so I would have expected the files should open in firefox '''without''' you needing to explicitly download them.
    Once the files are open in firefox, you will also get the option to save them permanently to a location on your computer. If you wish I suppose you could set the file type pdf to be associated with and be opened by firefox instead of with the Adobe Acrobat Reader, but that would just seem to be an additional complexity.

  • How to make audio file to use as ringtone on iPhone 5

    Does anyone know how to make a file and then make it a ringtone?

    Make sure iTunes prefs > Import settings is set to AAC.
    In iTunes, find the song you want and note the start/stop time you want the ring tone.
    Right click - get info, click the Options tab and set the start/stop times as above. (Note a 30 second max for ringtones)
    Right click - Create AAC version. This creates a new file.
    Drag this new file from the iTunes window to the desktop.
    Delete the new file from iTunes and also select Delete from hard drive.
    On the desktop, rename the file to what_ever_you_want.m4r (first part you can change to whatever you want & change the extension to .m4r).
    Drag the file back to the iTunes library at top left.
    Make sure iTunes prefs > General has Tones ticked.

  • How to make two files into one?

    I got two .iso files I would like to make into one file.
    What program can I use for this process? And step-by-step if possible.

    For disk images, if either of them is a read/write image, you can simply mount them both, drag the contents of one into the contents of the other, and unmount again. (Edit: just re-read your post; .ISO files are read-only so you will need to either follow the below instructions, or convert the ISO to a read/write DMG by dragging it into the left panel of Disk Utility and using the Images-Convert menu.)
    If they are both read-only, you'll need to create another disk image to contain them - use Disk Utility for this (File - New - Blank Disk Image), set the required size and properties, and once it's mounted, drag the contents of both .ISO images into it.
    Matt
    Message was edited by: Matt Clifton

  • How to: make one or two partions at a raid system?

    Hey
    how can i make one or more a partions at a raid system?
    i will make the partions at a 250gb raid. one with 120gb for the bootsector, and the other for documents, etc.
    is there a hwo to anywhere? dont find one?
    please read my second question.... 2 raids at one mac pro?
    regarads

    O.K., i was looking the hole day to get that partions on a raid working.
    to make the partions on each HD with the same volume, this is no problem. when you then create the first raid, works fine. but when you make the second raid, you get a massage, that this raid is not found.
    then you see both raids at the disc utilty, but only at the first you seen the volumen down under, by the second not. the first works, the second is not avabiele.
    so, now i have only one big mirrowed raid for my boot sector, and its runs fast, quick and without big noise... thats what i want, and the second big raid for my files.
    2 raids at one mac pro with 4 hd. one with 2 x 250 gb hd for the bootsector, and the other with 2 x 500gb for files
    thx to all, and you kappy
    regards

Maybe you are looking for