修复因为.net版本升级后,DESDecrypt的bug #66
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
由于.net升级后,CryptoStream的行为更加规范,CryptoStream 内部以“加密块”为单位进行解密,它一次只解密一个完整的块(例如 DES/3DES 块大小为 8 字节),即使底层数据流有更多数据,它也不会一次性全部读取。
单元测试中用的 var srcString = "test DES encrypt"; 正好满足块大小为 8 字节,测试可以通过。
修改为var srcString = "test DES encrypt -t";后测试失败,原始字符串通过DESEncrypt后再进行DESDecrypt,并不能得到原始字符串
错误是由于使用了cryptoStream.Read方法,改为使用cryptoStream.CopyTo(outputStream)进行修复