【问题标题】:JAVA - Decipher "DES" encrypted random numberJAVA - 解密“DES”加密随机数
【发布时间】:2012-07-06 19:31:03
【问题描述】:

我想知道如何破译使用特定密钥进行 DES/CBC 加密的随机数。

我的协议规定如下: 我正在发送 KeyNo(例如 0x00) 发送 KeyNo 后,我得到一个 8 字节(DES)随机数。这个随机数是用选定的密钥加密的。

我的问题是如何破译收到的数据,使用 Cipher 找到随机数

谢谢。

【问题讨论】:

标签: java encryption des


【解决方案1】:

要解密 DES 加密流,只需:

Key key = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(bytesOfThe Key)); // bytesOfTheKey should be 8 bytes long
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
return new CipherInputStream(inputStream, cipher);

您可能还对适用于 byteBuffers 的 doFinal 方法感兴趣。

【讨论】:

  • 我想我必须为 cipher.init 生成密钥。我怎么做?我有密钥为 00h 的加密随机数,我有它像 byte[] enciphered = { 12 A7 2B 8C 6E BB 93 40}
  • 有没有办法将解密后的内容返回为 8 字节数组?而不是输入流
  • 我收到 ShortBufferException Exception in thread "main" javax.crypto.ShortBufferException: Output buffer is null at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..) at com.sun.crypto.provider.DESCipher.engineDoFinal(DashoA13*..) at javax.crypto.Cipher.doFinal(DashoA13*..) 这就是我所做的告诉我它是否错误:` cipher.doFinal(INPUT_ENCIPHERED, 0, 8, output); System.out.println("OUTPUT: "+output.length);` 其中 byte[] INPUT_ENCIPHERED = 加密输入和输出定义为 byte[] 输出;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-06
  • 2014-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
相关资源
最近更新 更多