[英]I am using PyNacl at the backend for digital signatures. Which library should I use at frontend?
I have created an API that validates data based on PyNacl at the backend.我创建了一个 API,它在后端基于 PyNacl 验证数据。 I am accepting length 64 hexadecimal-encoded sender and recipient account numbers for my simple Crypto API and validating the signature based on PyNacl library.我为我的简单 Crypto API 接受长度为 64 的十六进制编码的发件人和收件人帐号,并基于 PyNacl 库验证签名。 I was wondering what Javascript library to use on my frontend so that the data I send using my React-based, it is coherent to my backend API.我想知道在我的前端使用什么 Javascript 库,以便我使用基于 React 发送的数据与我的后端 API 保持一致。 I looked at tweetnacl , but am not sure if they have the same working pattern.我查看了tweetnacl ,但不确定它们是否具有相同的工作模式。 Can you give me some information about whether or not I can use tweetnacl, or will I have to create a python script that uses PyNacl to generate Signing Keys / Verify Keys, and signs the message?你能给我一些关于我是否可以使用 tweetnacl 的信息,还是我必须创建一个 python 脚本,该脚本使用 PyNacl 生成签名密钥/验证密钥,并对消息进行签名?
Thanks.谢谢。
Update!更新! We have been successful at passing files between TweetLua and PyNaCl, The person writing the Lua side of the code had an "off by one" error (silly? but aren't most of our errors.), Once we got the right pieces in their proper places.我们已经成功地在 TweetLua 和 PyNaCl 之间传递文件,编写代码的 Lua 端的人有一个“off by one”错误(愚蠢?但不是我们的大部分错误。),一旦我们得到了正确的部分他们应有的地方。 it was a snap.这是一个瞬间。
I know the use of Lua instead of JavaScript isn't a perfect match to this question, but I hope that people who find this will get some use all the same.我知道使用 Lua 而不是 JavaScript 不是这个问题的完美匹配,但我希望发现这个问题的人会得到一些相同的使用。 It boils down to: Yes, TweetNaCl and PyNaCl are compatible, just as you'd expect.归结为:是的,正如您所期望的那样,TweetNaCl 和 PyNaCl 是兼容的。
Important element in this process:此过程中的重要元素:
Lua encryption: Lua 加密:
local function main(flag, files, keys)
local pt = chunkpt(flag, files) # We broke large files down
files.fout_size = companyfilesize(flag, pt)
files.fout = assert(io.open(flag.outfile, "wb"))
local current = files.fout:seek()
files.fout:seek("set", files.fout_size - 1)
files.fout:write("x")
files.fout:seek("set", current)
local err
local ct = {}
local nonce = {}
local mac = {}
local root
local nonceroot
local macroot
local n = #pt
for i = n, 1, -1 do
nonce[i] = nacl.randombytes(NONCE_LEN)
if i == n then
ct[i], err = nacl.box(pt[i], nonce[i], keys.p_rx, keys.k)
if err ~= nil then error("boxing error") end
else
ct[i], err = nacl.box(pt[i] .. nonce[i + 1] .. mac[i + 1], nonce[i],
keys.p_rx, keys.k)
if err ~= nil then error("boxing error") end
end
mac[i] = ct[i]:sub(1, MAC_LEN)
ct[i] = ct[i]:sub(MAC_LEN + 1, -1)
end
files.fout:seek("set", 0)
local header = header_info
files.fout:write(header)
files.fout:write(keys.p_tx)
files.fout:write(nonce[1])
files.fout:write(mac[1])
files.fout:write(ct[1])
files.fin:close()
files.fout:close()
return 0
end
Python decryption: Python解密:
def decrypt_box():
with open("encrypted_file.companybox", 'rb') as f:
header = f.read(16) # We use this for internal info
senderPubKey = f.read(32)
cyphertext = f.read()
f.close()
# Import the secret key for use in the decryption
imported_private_key = nacl.public.PrivateKey(BOB_SECRET_KEY)
# Import the public key we just found in the file
imported_public_key = nacl.public.PublicKey(senderPubKey)
# Make a box with the 2 keys
plain_box = Box(imported_private_key, imported_public_key)
# Pass the remaining text (that includes the Nonce and MAC) to decode
plain = plain_box.decrypt(cyphertext)
print(plain.decode('utf-8'))
Previous response: So far as I can tell, no, TweetNaCl and PyNaCl are not compatible.以前的回应:据我所知,不,TweetNaCl 和 PyNaCl 不兼容。 My group is attempting to encrypt a file with c# TweetNaCl and decrypt with python, and I always end up with a general nacl.exceptions.CryptoError: An error occurred trying to decrypt the message
.我的小组正在尝试使用 c# TweetNaCl 加密文件并使用 python 解密,我总是以一般nacl.exceptions.CryptoError: An error occurred trying to decrypt the message
结束。 If you / someone else figures out a solution, I'd love to hear it!如果您/其他人想出了一个解决方案,我很想听听!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.