我正在尝试移植一个使用 scrypt 生成密码的 python 脚本。
import pylibscrypt
scrypt = pylibscrypt.scrypt
password = 'test123'.encode("utf_16_be", "replace")
salt = '384eaed91035763e'.decode('hex')
key = scrypt(password, salt, 16384, 8, 1, 32)
print (key.encode('hex'))
结果应该是:9f2117416c7b2de9419a81c4625a28e40c16ac92aaa3000bb2c35844b3839eb1
在 C 中,我使用 libsodium crypto_pwhash_scryptsalsa208sha256_ll() 函数。
如果我尝试从该变量传递密码:
const uint8_t password[] = "test123";
我没有得到相同的密钥。我试图从 python 脚本中删除 ".encode("utf_16_be", "replace")" ,然后得到相同的结果。
那么如何将我的 C 变量转换为与 python 变量相同的变量呢?
编辑:原始软件是 Java 并且似乎将字符串编码为 UTF-16 大端。现在我需要将 C 字符串编码为相同的格式。