我基本上使用http://www.avajava.com/tutorials/lessons/how-do-i-encrypt-and-decrypt-files-using-des.html中的代码来加密应用程序,但我希望能够选择操作模式所以我添加了这个:
private String key;
private static String algorithmMode;
public DESCrypt(String password, String algorithmMode) {
this.key = password;
this.algorithmMode = "DES/" + algorithmMode + "/PKCS5Padding";
}
Run Code Online (Sandbox Code Playgroud)
主要看起来像这样:
public static void main(String[] args) {
try {
DESCrypt des = new DESCrypt("12345678", algorithmMode);
// FileInputStream fis1 = new FileInputStream("d:\\_test.txt");
// FileOutputStream fos1 = new FileOutputStream("d:\\_test.txt.des");
// des.encrypt(fis1, fos1);
FileInputStream fis = new FileInputStream("d:\\_test.txt.des");
FileOutputStream fos = new FileOutputStream("d:\\_test.txt");
des.decrypt(fis, fos);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
正如我在标题中所说的那样它可以与ECB一起使用但是在其他模式下我只能加密.
我在面试时问了这个问题.假设我必须检查第3位:
a=0x9004;
Run Code Online (Sandbox Code Playgroud)
我说过的
if((a<<13>>15)^1==1)
printf("bit 3 is not set");
else
printf("bit 3 is set");
Run Code Online (Sandbox Code Playgroud)
但我觉得这不是他们想要的.
我们假设我有这个代码:
char *pointer;
unsigned int a;
pointer = a;
Run Code Online (Sandbox Code Playgroud)
对我来说,这不会产生任何问题,但我会收到以下警告:
assignment makes pointer from integer without a cast
Run Code Online (Sandbox Code Playgroud)
为什么使用演员阵容更好?我正在使用32位机器.
编辑:通过"这不会产生任何问题",我说它编译并指针存储变量的值a.
编辑:变量a实际上会存储一个地址.