how to use DES in java?

J

JTL.zheng

I want to write codes to encrypt file using DES

something like:
public File encryptDES(File inputFile,String DES_key)
the DES_key is 56bits

I know nothing about it
could you introduce some resources about how to write this funcition
is there any class in java?
where I can learn to use them?

Thank you very much in advance
 
L

Luc The Perverse

JTL.zheng said:
I want to write codes to encrypt file using DES

something like:
public File encryptDES(File inputFile,String DES_key)
the DES_key is 56bits

I know nothing about it
could you introduce some resources about how to write this funcition
is there any class in java?
where I can learn to use them?

Why are you using DES?

You should use AES - and finding an example is as easy as searching google

DES is simply not secure - AES is, to the best of our knowledge.
 
R

redbox

"JTL.zheng дµÀ£º
"
I want to write codes to encrypt file using DES

something like:
public File encryptDES(File inputFile,String DES_key)
the DES_key is 56bits

I know nothing about it
could you introduce some resources about how to write this funcition
is there any class in java?
where I can learn to use them?

Thank you very much in advance

I am not good at english .i hope code can say instead for me;
exceped it is valueable for you

public void encrypt(SecretKey key,File fin,File fout) throws Exception{
FileInputStream in=new FileInputStream(fin);
FileOutputStream out=new FileOutputStream(fout);
Cipher desCipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos=new CipherOutputStream(out,desCipher);
byte[] enBuffer=new byte[4096];
int n;
while((n=in.read(enBuffer))!=-1){
cos.write(enBuffer, 0, n);

}
cos.close();
}
 
R

redbox

"JTL.zheng дµÀ£º
"
I want to write codes to encrypt file using DES

something like:
public File encryptDES(File inputFile,String DES_key)
the DES_key is 56bits

I know nothing about it
could you introduce some resources about how to write this funcition
is there any class in java?
where I can learn to use them?

Thank you very much in advance

I am not good at english .i hope code can say instead for me;
exceped it is valueable for you

public void encrypt(SecretKey key,File fin,File fout) throws Exception{
FileInputStream in=new FileInputStream(fin);
FileOutputStream out=new FileOutputStream(fout);
Cipher desCipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos=new CipherOutputStream(out,desCipher);
byte[] enBuffer=new byte[4096];
int n;
while((n=in.read(enBuffer))!=-1){
cos.write(enBuffer, 0, n);

}
cos.close();
}
 
J

JTL.zheng

Thank you very much for your help

to: Luc The Perverse
as I am learning DES now ,I want to try it
we will learn AES weeks later.

to redbox
Thank you for your codes
could you explain some code for me...
encrypt(SecretKey key,File fin,File fout)
how can I use this SecretKey class?
just: SecretKey s=new SecretKey("key1234"); ?
Cipher desCipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
is this exactly the DES ,or ECB/PKCS5Padding?
desCipher.init(Cipher.ENCRYPT_MODE, key);
we set the key here , right?

could you give me some codes for decrypt

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top