小编Sto*_*Dan的帖子

当使用除ECB之外的其他模式时,使用DES进行解密会抛出"InvalidKeyException:参数缺失"

我基本上使用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一起使用但是在其他模式下我只能加密.

java des ecb

3
推荐指数
1
解决办法
7251
查看次数

在C中,如何检查是否使用XOR设置了一个位?

我在面试时问了这个问题.假设我必须检查第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)

但我觉得这不是他们想要的.

c bit-manipulation

3
推荐指数
2
解决办法
188
查看次数

为指针分配整数时,为什么使用强制转换更好?

我们假设我有这个代码:

  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实际上会存储一个地址.

c pointers casting

-2
推荐指数
2
解决办法
163
查看次数

标签 统计

c ×2

bit-manipulation ×1

casting ×1

des ×1

ecb ×1

java ×1

pointers ×1