Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

a little question about DES

Thread view: 
JTL.zheng - 26 Dec 2006 16:12 GMT
my codes is:
-----------------------
static public void encrypt(String keyStr, File fin, File fout) {
   try {
     SecretKey key = new SecretKeySpec(keyStr.getBytes(), "DES");
     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();
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
--------------------

as we know, the DES's key is 56bits

but when I used:
encrypt("1234567", new File("E:/1.txt"), new File("E:/2.txt"));
or
encrypt("123456789", new File("E:/1.txt"), new File("E:/2.txt"));

it throw Exception:
Invalid key length: 7 bytes
or
Invalid key length: 9 bytes

but
encrypt("12345678", new File("E:/1.txt"), new File("E:/2.txt"));
is OK

it means that the key must be 64bits,but DES's key is 56bits,isn't it?
why I used 56bits key it throw Exception?
Alan Krueger - 26 Dec 2006 17:11 GMT
> it means that the key must be 64bits,but DES's key is 56bits,isn't it?
> why I used 56bits key it throw Exception?

http://www.exampledepot.com/egs/javax.crypto/MakeDes.html?l=rel


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.