如果我有一个基于libsodium的公钥,如何将其与OpenSSL工具一起使用来加密文本,并让另一个基于钠的端点能够解密它?
也就是说,在x.astype('int16').tofile('file.int16') # 572 MB
df.to_csv("file.csv", index=False, header=None) # 1.1 GB
df.to_parquet("file.parq", index=False, compression="GZIP") # 556M
(也许是openssl
)命令中使用与libsodium相同的密码和参数。
为此,我有一个C#示例:
pkeyutl
它应在带有Sodium.Core软件包的.NET Core 3.1中运行。我已经使用this dotnet fiddle在线运行了它(因此根本不需要额外的工具来检查此代码)。
现在在 bash shell 中,如果我尝试这样的操作:
using System;
public class Program
{
public static void Main()
{
var secretValue = System.Text.Encoding.UTF8.GetBytes("mySecret");
var publicKey = Convert.FromBase64String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvvcCU=");
var sealedPublicKeyBox = Sodium.SealedPublicKeyBox.Create(secretValue, publicKey);
Console.WriteLine(Convert.ToBase64String(sealedPublicKeyBox));
}
}
OpenSSL与此失败:
secret="text to be encrypted"
pubkey="2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvvcCU="
echo "-----BEGIN PUBLIC KEY-----
${pubkey}
-----END PUBLIC KEY-----" > pkey.tmp
echo "${secret}" | openssl pkeyutl -encrypt -pubin -inkey pkey.tmp | base64
如果我删除了临时公钥文件中的周围的行,则会得到:
25769803792:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:crypto/asn1/asn1_lib.c:91:
25769803792:error:0D068066:asn1 encoding routines:asn1_check_tlen:bad object header:crypto/asn1/tasn_dec.c:1118:
25769803792:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:290:Type=X509_PUBKEY
25769803792:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:crypto/pem/pem_oth.c:33:
对于我能找到的,OpenSSL does support the ciphers and algorithms used by libsodium;我想我只是不知道如何有效地告诉OpenSSL它们是什么...