- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直试图在PHP中为CBC实现Ciphertext Stealing(CTS)。
在下面引用两个链接
How can I encrypt/decrypt data using AES CBC+CTS (ciphertext stealing) mode in PHP?
和
http://en.wikipedia.org/wiki/Ciphertext_stealing
我对XOR的最后一步和最简单的步骤感到困惑和困惑。
我知道这很愚蠢,但是尝试了所有组合之后,我不知道我在想什么。
代码如下。
// 1. Decrypt the second to last ciphertext block, using zeros as IV.
$second_to_last_cipher_block = substr($cipher_text, strlen($cipher_text) - 32, 16);
$second_to_last_plain = @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $second_to_last_cipher_block, MCRYPT_MODE_CBC);
// 2. Pad the ciphertext to the nearest multiple of the block size using the last B-M
// bits of block cipher decryption of the second-to-last ciphertext block.
$n = 16 - (strlen($cipher_text) % 16);
$cipher_text .= substr($second_to_last_plain, -$n);
// 3. Swap the last two ciphertext blocks.
$cipher_block_last = substr($cipher_text, -16);
$cipher_block_second_last = substr($cipher_text, -32, 16);
$cipher_text = substr($cipher_text, 0, -32) . $cipher_block_last . $cipher_block_second_last;
// 4. Decrypt the ciphertext using the standard CBC mode up to the last block.
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($cipher, $key, $iv);
$plain_text = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipher_text, MCRYPT_MODE_CBC , $iv);
// 5. Exclusive-OR the last ciphertext (was already decrypted in step 1) with the second last ciphertext.
// ???
// echo $??? ^ $???;
最佳答案
我发现具体的用例对理解算法非常有帮助。这里有2个用例,以及分步演练。
两种用例的起点。
这些用例假定您要解密的消息使用具有CBC链接模式和密文窃取的AES-256进行块量化。为了生成这些用例,我使用了Delphi 2010编译器和TurboPower LockBox3库(SVN修订版243)。在下面的内容中,我使用这样的表示法...
IV := [16] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X := [2] 03 10
key = [32] 0D EE 8F 9F 8B 0B D4 A1 17 59 FA 05 FA 2B 65 4F 23 00 29 26 0D EE 8F 9F 8B 0B D4 A1 17 59 FA 05
password = (UTF-8) 'Your lips are smoother than vasoline.'
Message = (UTF-8) 'Leeeeeeeeeroy Jenkins!'
TRandomStream.Instance.Seed := 1;
ciphertext = [30] 01 00 00 00 00 00 00 00 17 5C C0 97 FF EF 63 5A 88 83 6C 00 62 BF 87 E5 1D 66 DB 97 2E 2C
(base64 equivalent ='AQAAAAAAAAAXXMCX/+9jWoiDbABiv4flHWbbly4s')
IV = [16] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c[0] = [16] 17 5C C0 97 FF EF 63 5A 88 83 6C 00 62 BF 87 E5
c[1] = [6] 1D 66 DB 97 2E 2C
CV = [16] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
m[n] := Decrypt( c[n]) XOR CV;
CV[n+1] := c[n]
m[n] := Decrypt( c[n]) XOR CV;
CV[n+1] := CV[n] // Unchanged!
CV = [16] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c[0] = [16] 17 5C C0 97 FF EF 63 5A 88 83 6C 00 62 BF 87 E5
Decrypt(c[0]) = [16] 6F 6B 69 6E 73 21 F0 7B 79 F2 AF 27 B1 52 D6 0B
m[0] := Decrypt(c[0]) XOR CV = [16] 6E 6B 69 6E 73 21 F0 7B 79 F2 AF 27 B1 52 D6 0B
y := c[N-1] | LastBytes( m[N-2], BlockSize-Length(c[N-1]));
m[N-1] := Decrypt( y) XOR CV
c[1] = [6] 1D 66 DB 97 2E 2C
y := c[1] | LastBytes( m[0], 10)
y = [16] 1D 66 DB 97 2E 2C F0 7B 79 F2 AF 27 B1 52 D6 0B
Decrypt( y) = [16]= 4D 65 65 65 65 65 65 65 65 65 72 6F 79 20 4A 65
m[1] := Decrypt(y) XOR CV
m[1] = [16] 4C 65 65 65 65 65 65 65 65 65 72 6F 79 20 4A 65
m[1] = [16] 4C 65 65 65 65 65 65 65 65 65 72 6F 79 20 4A 65
FirstBytes( m[0], 6) = 6E 6B 69 6E 73 21
[22] 4C 65 65 65 65 65 65 65 65 65 72 6F 79 20 4A 65 6E 6B 69 6E 73 21
Ciphertext = [40] 01 00 00 00 00 00 00 00 70 76 12 58 4E 38 1C E1 92 CA 34 FB 9A 37 C5 0A 75 F2 0B 46 A1 DF 56 60 D4 5C 76 4B 52 19 DA 83
which is encoded base64 as 'AQAAAAAAAABwdhJYTjgc4ZLKNPuaN8UKdfILRqHfVmDUXHZLUhnagw=='
IV = [16] 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c[0] = [16] 70 76 12 58 4E 38 1C E1 92 CA 34 FB 9A 37 C5 0A
c[1] = [16] 75 F2 0B 46 A1 DF 56 60 D4 5C 76 4B 52 19 DA 83
Decrypt(c[0]) = [16] 45 61 6E 63 65 20 74 68 65 6E 2C 20 77 68 65 72
m[0] := Decrypt(c[0]) XOR CV = [16] 44 61 6E 63 65 20 74 68 65 6E 2C 20 77 68 65 72
Next CV := c[0] = [16] 70 76 12 58 4E 38 1C E1 92 CA 34 FB 9A 37 C5 0A
Decrypt(c[1]) = [16] 75 F2 0B 46 A1 DF 56 60 D4 5C 76 4B 52 19 DA 83
m[1] := Decrypt(c[1]) XOR CV = [16] 65 65 76 65 72 20 79 6F 75 20 6D 61 79 20 62 65
m[0] = [16] 44 61 6E 63 65 20 74 68 65 6E 2C 20 77 68 65 72
m[1] = [16] 65 65 76 65 72 20 79 6F 75 20 6D 61 79 20 62 65
[32] 44 61 6E 63 65 20 74 68 65 6E 2C 20 77 68 65 72 65 65 76 65 72 20 79 6F 75 20 6D 61 79 20 62 65
关于php - PHP通过CBC实现密文窃取(CTS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328320/
如果您了解 Android 兼容性测试套件。请将CTS源码下载、环境搭建、搭建和执行等信息发给我们。 最佳答案 您可以找到关于 setting up and running CTS 的所有信息在这里。
我有一个奇怪的问题,我正在做 cts:uri 和 cts:search.. 而我的 cts:uris 给了我 7 个结果,而 cts:search 只给了 3 个结果.. 不知道我做错了什么,希望有人
cts:count有什么区别, cts:frequency , fn:count在 MarkLogic 中? 你能用例子支持我吗? 最佳答案 cts:count 已弃用,它被设计为采用词典函数返回的一
我使用下面提到的命令为 64 位目标运行相机 Android 7 CTS,但所有 CTS 首先为 64 位目标运行两次,然后为 32 位目标运行两次。 run cts-camera --skip-pr
我们正在开发一个存储大量数据的企业应用程序。在我们的应用程序中,我们强制用户创建多个路径范围索引以加快搜索速度。 早些时候,我们利用路径范围索引来加快搜索速度,使用 cts:路径范围查询()但现在我发
我正在尝试运行 android CTS 测试。 这是我运行时出现的错误: E/TestInvocation: Unexpected contents in directory /tmp/android
我一直试图在PHP中为CBC实现Ciphertext Stealing(CTS)。 在下面引用两个链接 How can I encrypt/decrypt data using AES CBC+CTS
我一直在尝试在从源代码构建的 Android 副本上使用 Android CTS 包,但我遇到了很多测试超时然后失败的问题。 我是从标签 android-cts-verifier-4.0.3_r1 构
Android CTS 文档如下所述。 “要对在多个设备上运行的计划测试进行 fragment :- run cts -plan CTS --shards 那我就这么干。但我做不到。PC肯定能识别多
由于英语不是我的母语,我想知道单词 Common Type System (CTS) 的确切语义。它们是否可以解释为通用类型系统或 .NET Framework 通用的类型系统?也就是系统通用还是类型
我的要求是获取数据库中可用文档的总数。 cts.estimate( cts.trueQuery() ) 当我执行上述查询时,它返回 1283265文档计数但是当我从 qconsole 浏览数据库时
鉴于此查询: for $d in cts:search( fn:doc(), cts:and-query( ( cts:c
在marklogic中,三元组可以嵌入到现有文档中。我如何使用 cts 搜索查询返回文档。文档的示例可以是 Testing Approved http://myco
如何终止正在运行的 CTS 实例。假设一个 CTS 实例正在运行在一个终端上,如果我们突然关闭那个终端,那个 CTS实例不会关闭,当我们尝试再次启动 CTS 时新终端,我们收到此错误 [CTS_ERR
我已经学会了如何构建 CTS 并执行它。 现在,我想知道CTS工作流程的过程。任何人都可以解释一下或分享您如何在 CTS 中添加测试包然后构建新的 CTS 来测试您的应用程序的经验吗? 我尝试在谷歌中
我正在尝试找到一种方法,让 cts-tradefed 在出现故障时抓取 logcat 文件,并且可能还会获取错误报告。主要是因为当我运行完整的 CTS 计划时,最后需要很长的日志是没有用的 最佳答案
我发现了一些 CTS 错误,如下所示: 兼容性测试用例:CtsAppTestCases 包名称:android.app.cts.DialogTest 错误: -- testContextMenu
我在我的机器上连接了 2 个设备,我想在这两个设备上运行 Google CTS。但这里的问题是,每当我运行 ./startcts 命令时,两个设备都会连接到 session 。 我的要求: 我想在两台
我正在运行 Android 2.2 的模拟器上运行 Android CTS Android 测试计划。 但是大部分测试用例都显示超时,错误显示com.android.ddmlib.ShellComma
我们如何完成以下任务: 在运行时我们可以跳过任何包或案例...? 最佳答案 您不能直接在 CTS 中跳过特定的测试用例。为此,您必须手动执行要执行的测试用例。由于有成千上万的测试用例,因此执行测试用例
我是一名优秀的程序员,十分优秀!