简体   繁体   English

没有ASN.1编码的C#RSA签名

[英]C# RSA signing without ASN.1 encoding

First of all, I need to replicate echo -n "someUnhashedData" | openssl pkeyutl -sign -inkey rsa.key | base64 -w 0 首先,我需要复制echo -n "someUnhashedData" | openssl pkeyutl -sign -inkey rsa.key | base64 -w 0 echo -n "someUnhashedData" | openssl pkeyutl -sign -inkey rsa.key | base64 -w 0 echo -n "someUnhashedData" | openssl pkeyutl -sign -inkey rsa.key | base64 -w 0 functionality in C# code. C#代码中的echo -n "someUnhashedData" | openssl pkeyutl -sign -inkey rsa.key | base64 -w 0功能。 I managed to load private key into System.Security.Cryptography.RSACryptoServiceProvider and call SignData , but the result I'm getting is different from that of openssl pkeyutl . 我设法将私钥加载到System.Security.Cryptography.RSACryptoServiceProvider并调用SignData ,但是我得到的结果与openssl pkeyutl的结果不同。

As far as I understand, per this post and this RFC when pkeyutl -sign is called without -pkeyopt digest:hashFunc openssl does not bundle data with digest function identifier and skips ASN.1 encoding. 据我明白,每此篇这个RFCpkeyutl -sign被不带-pkeyopt digest:hashFunc OpenSSL的不捆绑与消化功能标识符数据,并跳过ASN.1编码。 This means that raw data is padded and encrypted. 这意味着原始数据将被填充和加密。 This tool seems to confirm that, decrypted signature looks like padded plaintext data. 该工具似乎可以确认解密后的签名看起来像是填充的纯文本数据。

So how do I do that with C#? 那么如何使用C#做到这一点呢? All functions from RSACryptoServiceProvider require to specify hash algorithm and encode signature before encryption. RSACryptoServiceProvider所有功能都要求在加密之前指定哈希算法并编码签名。 Is there something I'm missing or will I have to write my own RSA private encryption? 我是否缺少某些东西,还是必须编写自己的RSA私有加密?

.NET has no inbox API to performing "raw RSA". .NET没有执行“原始RSA”的收件箱API。 If you need that capability to match an existing bug in another RSA consumer you would have to make a new class which P/Invokes down to the system cryptographic libraries (or otherwise provides the functionality you seek) 如果您需要与其他RSA使用者中的现有错误相匹配的功能,则必须创建一个新类,将P / Invokes到系统密码库中(或以其他方式提供您想要的功能)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM