Encryption 如何在netbeans java中使用bouncy castle(DES)加密和解密文件?

Encryption 如何在netbeans java中使用bouncy castle(DES)加密和解密文件?,encryption,cryptography,bouncycastle,des,3des,Encryption,Cryptography,Bouncycastle,Des,3des,如何使用bouncy castle(DESEngine)加密和解密文件(而不是字符串)? 我以前搜索过,但找不到帮助。对不起,我自己解决了这个问题。这是我的密码: tesbunciy.java 包装有弹性; 导入org.bouncycastle.crypto.*; 导入org.bouncycastle.crypto.engines.*; 导入org.bouncycastle.crypto.modes.*; 导入org.bouncycastle.crypto.paddings.*; 导入org.b

如何使用bouncy castle(DESEngine)加密和解密文件(而不是字符串)?
我以前搜索过,但找不到帮助。

对不起,我自己解决了这个问题。这是我的密码:

tesbunciy.java
包装有弹性;
导入org.bouncycastle.crypto.*;
导入org.bouncycastle.crypto.engines.*;
导入org.bouncycastle.crypto.modes.*;
导入org.bouncycastle.crypto.paddings.*;
导入org.bouncycastle.crypto.params.*;
公营课{
区块密码引擎=新的DESEngine();
公共字节[]加密(字符串密钥,字节[]明文){
byte[]key=keys.getBytes();
字节[]ptBytes=纯文本;
BufferedBlockCipher cipher=新的填充BufferedBlockCipher(新的CBCBlockCipher(引擎));
init(true,新的键参数(key));
byte[]rv=新字节[cipher.getOutputSize(ptBytes.length)];
int tam=cipher.processBytes(ptBytes,0,ptBytes.length,rv,0);
试一试{
密码doFinal(rv,tam);
}捕获(例外ce){
printStackTrace();
}
返回rv;
}
公共字节[]解密(字符串键2,字节[]密文){
byte[]key=key2.getBytes();
BufferedBlockCipher cipher=新的填充BufferedBlockCipher(新的CBCBlockCipher(引擎));
init(false,新的KeyParameter(key));
byte[]rv=新字节[cipher.getOutputSize(cipherText.length)];
int tam=cipher.processBytes(密文,0,密文.length,rv,0);
试一试{
密码doFinal(rv,tam);
}捕获(例外ce){
printStackTrace();
}
返回rv;
}
}
Main.java

包弹性;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入javax.crypto.Cipher;
导入javax.crypto.CipherOutputStream;
导入javax.crypto.spec.SecretKeySpec;
公共班机{
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args)引发异常{
File File=新文件(“sql/design.jpg”);
File file2=新文件(“sql/design2.jpg”);
试一试{
FileInputStream imageInFile=新的FileInputStream(文件);
字节imageData[]=新字节[(int)file.length()];
imageInFile.read(图像数据);
Tesbouncy esource=新的Tesbouncy();
String key=“12345678”;
字节[]enc=esource.Encrypt(密钥、图像数据);
字节[]imageByteArray=enc;
FileOutputStream imageOutFile=新的FileOutputStream(“sql/design2.jpg”);
imageOutFile.write(imageByteArray);
imageinfle.close();
imageOutFile.close();
FileInputStream imageInFile2=新的FileInputStream(file2);
字节imageData2[]=新字节[(int)file2.length()];
imageInFile2.read(imageData2);
Tesbouncy esource2=新的Tesbouncy();
字符串键2=“12345678”;
字节[]cad2=imageData2;
byte[]keyb2=key2.getBytes();
字节[]des2=esource2.Decrypt(键2,cad2);
字节[]imageByteArray2=des2;
FileOutputStream ImageOutpile2=新的FileOutputStream(“sql/design3.jpg”);
imageOutFile2.写入(imageByteArray2);
imageInFile2.close();
imageOutFile2.close();
System.out.println(“图像成功还原!”);
}catch(filenotfounde异常){
System.out.println(“未找到图像”+e);
}捕获(ioe异常ioe){
System.out.println(“读取图像时异常”+ioe);
}
}
}

您应该向我们展示您以前实际尝试过的内容。你怎么知道这台发动机是你需要的?你想实现什么?为什么你要使用DES而不是像AES这样的安全密码?对不起,我已经自己解决了。我很快就会把我的答案贴出来。我想尝试3DES,但在DES'Hi的每个部分都做了一些修改后,我正在尝试将您的代码转换为C#,BouncyCastle assembly,CMIIW中没有块密码