我像这样加密:
plaintextstr := "0000000000000thankustackoverflow"
plaintext := []byte(plaintextstr)
key := []byte("abcdefghijklmnop")
block, _ := aes.NewCipher(key)
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
iv := ciphertext[:aes.BlockSize]
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(ciphertext[aes.BlockSize:], plaintext)
fmt.Printf("%x\n", ciphertext)
输出是:
000000000000000000000000000000000d77aa6646bb541808ed23c88d4b06d30f42b01d6e806a02b29086bc82892334f
但是用 PHP 编写的此代码的另一个版本的输出是:
d77aa6646bb541808ed23c88d4b06d30f42b01d6e806a02b29086bc82892334fbf21ea861abbc3d72e44731978bb76c2
请注意,00000000000000000000000000000000 是末尾缺失数据的确切长度。它是 32,即原始纯文本字符串的大小。知道如何在 golang 中左移所有内容并获取丢失的数据吗?
PHP:
<?php
include('Crypt/AES.php');
$aes = new Crypt_AES();
$aes->setKey('abcdefghijklmnop');
echo bin2hex($aes->encrypt("0000000000000thankustackoverflow"));
https://github.com/andrewarrow/phpseclib1/blob/master/Crypt/AES.php https://github.com/andrewarrow/phpseclib1/blob/master/Crypt/Rijndael.php
调试php输出:
00000000000000000000000000000000 <--- IV
30303030303030303030303030746861 block 0
d77aa6646bb541808ed23c88d4b06d30 crypted 0
6e6b75737461636b6f766572666c6f77 block 16
f42b01d6e806a02b29086bc82892334f crypted 16
10101010101010101010101010101010 block 32
bf21ea861abbc3d72e44731978bb76c2 crypted 32
米脂
忽然笑
相关分类