[英]is this possible to encrypt and decrypt a zip file using DES algorithm in java
我必須使用存儲在文本文件中的KEY使用DES算法對zip文件進行加密和解密。加密和解密算法都從文本文件中獲取密鑰來執行相應的功能。
是否有任何內置程序包可用於在Java中執行DES算法...
請指導我擺脫這個問題...
您可以使用javax.crypto包中的內容:
// read the key
FileInputStream fis = new FileInputStream(keyFile);
byte[] keyBytes = new byte[fis.available()];
fis.read(keyBytes);
SecretKeySpec spec = new SecretKeySpec(keyBytes, "DES");
// encrypt
Cipher encCipher = Cipher.getInstance("DES");
encCipher.init(Cipher.ENCRYPT_MODE, spec);
CipherInputStream cipherIn = new CipherInputStream(new FileInputStream(zipFile), encCipher);
FileChannel out = new FileOutputStream(encZipFile).getChannel();
out.transferFrom(Channels.newChannel(cipherIn), 0, Long.MAX_VALUE);
// decrypt
Cipher decCipher = Cipher.getInstance("DES");
decCipher.init(Cipher.DECRYPT_MODE, spec);
cipherIn = new CipherInputStream(new FileInputStream(encZipFile), decCipher);
out = new FileOutputStream(decZipFile).getChannel();
out.transferFrom(Channels.newChannel(cipherIn), 0, Long.MAX_VALUE);
有可能,最好您堅決追求彈性,他們為此提供了API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.