Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   a little question about DES (http://www.velocityreviews.com/forums/t389660-a-little-question-about-des.html)

JTL.zheng 12-26-2006 04:12 PM

a little question about DES
 
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 12-26-2006 05:11 PM

Re: a little question about DES
 
JTL.zheng wrote:
> 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/java...Des.html?l=rel


All times are GMT. The time now is 01:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.