简体   繁体   English

获取密钥流-Java解密

[英]Getting keystream - Java Decryption

I am using Java's Cipher class for decryption. 我正在使用Java的Cipher类进行解密。

Couple of questions: 几个问题:

  1. Using DES decryption with OFB, for a multi-part decryption, is it possible to generate keystream in the first iteration but not use that keystream for the XORing but still feed the keystream into the next block cipher? 使用DES解密和OFB进行多部分解密,是否有可能在第一次迭代中生成密钥流,但不将该密钥流用于XOR运算,但仍将密钥流馈送到下一个块密码中?

My code is (briefly) as follows: 我的代码(简短地)如下:

desCipher = Cipher.getInstance("DES/OFB56/NoPadding");
desCipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameter);
for (i=0;i<subframeCount;i++){
// perform the skip iteration here
  if (firstFrame){
      byte[] dummy = new byte[7];
      dummy[0] = 1;dummy[1] = 12;dummy[2] = 12;dummy[3] = 15;dummy[4] = 26;dummy[5] = 12;dummy[6] = 12;
      desCipher.update(dummy);
  }
  if (not_last_frame){
      decryptedVCW = desCipher.update(vcwShift_E);
  }
  else{
      decryptedVCW = desCipher.doFinal(vcwShift_E);
  }

}

I am not sure if it is indeed skipping the XORing in the update(dummy) operation and then using the keystream for the next block cipher. 我不确定它是否确实会跳过update(dummy)操作中的XORing,然后将密钥流用于下一个分组密码。

  1. Is it possible to retrieve the keystream for each operation? 是否可以检索每个操作的密钥流? It would be good to see what is exactly being generated. 最好查看确切生成了什么。

Thanks Shiv 谢谢湿婆

  1. Yes, that's how OFB works: the output from the encryption (the keystream) is fed directly as input to the next block, so the XOR-ing part is independent from the encryption engine, just like a stream cipher. 是的,这就是OFB的工作方式:加密(密钥流)的输出直接作为输入馈送到下一个块,因此XOR-ing部分独立于加密引擎,就像流密码一样。

  2. Another way of getting the keystream than XOR-ing with the plaintext, is to XOR (or invoke update()/doFinal() ) with only zeroes, you will get the actual keystream. 除了对明文进行XOR运算以外,获取密钥流的另一种方法是对XOR(或仅使用零调用update()/doFinal() ),您将获得实际的密钥流。 Just in case you want to see what the keystream looks like. 以防万一您想查看密钥流的外观。 But your way will obviously work as well, I am just adding this for sake of completeness. 但是您的方式显然也可以工作,我只是为了完整性而添加此内容。

I found out that the first iteration is indeed skipping the XORing stage. 我发现第一次迭代确实跳过了XORing阶段。

The keystream can be found by XORing the plain text with the decryptedVCW (which should have been obvious to me) 可以通过将纯文本与解密的VCW异或来找到密钥流(这对我来说应该是显而易见的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM