gpt4 book ai didi

c# - 使用 2048 位 key 的 RSA 解密在 Windows Server 2012 r2 上为长度为 340 的加密文本提供了错误数据,而它在 Windows 8 上运行良好

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:49 25 4
gpt4 key购买 nike

  RSACryptoServiceProvider objRsaCrypto= new RSACryptoServiceProvider();
string xmlString = "<RSAKeyValue><Modulus>vafMwhQ1Z+zx1tpcUybDONf3M7IG8Xw6Q0eCsuWMRniqwUklnzndo9ExuAFC87oAywOcSSzSncLEgILxjiyNmnBe28whdDg+P1PJmDchmBIjzQKNpDIppOiaxGOUR8KqBwIMp24dZQtUqb9mElEEz5bOxZUwHLg2/fJ9bT+eE+VluHtYfuuS/nbhrvI6BHN2bm2CyITBAvT6loCm7mV/JZ0fT9nCsyn6rUsp+YCVbhrfMnyz9aW7NEkwncE7xz78LSIHaYgB19nPu5jkR6yUCLsNDV9wnOBjb1Xuh7NqTjt2yOAcH+Gt5ixukfKBROq67FlnQKZOa+mQNzkhytEeyw==</Modulus><Exponent>AQAB</Exponent><P>4tDAYRgWNcyB5dCN7kF8QUa4ddiw6siEblGnjcFpdrQLyJxFvCZ7Jlc/59Wmr8B/1G06coRla5NLBCtvh/Itovacfp00wNif5pBb/Tp9+quw5/GGSu/4/K/Ke0wQuhHdWNjzAriNxbpCRWD/EgzNngWS8KlufdymZyju6AWyEZk=</P><Q>1g8B7fQ3SMDZ2EyaiSscchj3lshJx9VR8EAN70aipu45LRsOWuHH7wTkfqp1LuB06LyCr7XLMwUQYrBM8mJOhtxsiissXe+Phw1kcXJo6hBrCPgfSKSkuHT8iR7OgZbzYA8zwMmr+m2WOuDsgxrQcb+hRVdC1QODqFb8C08YegM=</Q><DP>vW5Zbf4e9pmx142CLH3219HH12y9/aiwqi56QPNLML+Yo9iYiVaePdxa3DZdO6YLXRBI40HeLqVa3sWkJadHJDbRZxHG8FU73uWsXmcOtl/UpTLb1RRtICV1d9qEkdK/yiePdjNK/Nvd43HqNloJFLRVD7iCNo4lUD0ooxG2sek=</DP><DQ>BCeWaf/rcsYLdF9IQJFNpAlIBO0uQWqqhHc5zgMY9RR6l52G0czADKuTo8G7NIW2vy2pe6+TmhHnF4NEew/dZlCw6p2b5tbXek+QO4N09dYLvcjTEp3fdJUQsbifWXSMlLi20G8Zn2qxF8N107WZhhuqDaZ77ZZ737CQg8etOfE=</DQ><InverseQ>xEjq9mm61gofysxxgM6SnX5TQ5Lnpq0AvnsRBhQaatiGm8i+VnznMpk8zJgn/AspaYS62bFC/UdCd/b2VyXgZfBC/L1NdkIUNyOVAxNKhf95C4uQFFxe90RfuZjbbClFbm/tU7RmycHqciPXViI35tToF1CXMJsxd7q6M2iaXKc=</InverseQ><D>HVnfO/gBreRDJzOjDzFUDDOMK+F05qGJqMjj5sjUtUFOd9xYqLQ9Y3FoJuh3Ep4qKkEUSlTYAZdXbuYU+SJXBdw3KgAE+2YK6CUQ8XAy0ESaastm3U7wF/fxn8wjchmj07LS/4RwoycmQqD+7H3CZ1gZBwYILKGrzRBere4nCj/1i5LTbfweAMUo85KMfZDbGChlJUhd4vNiRPGmOeKCT1/xDAw/3ZKfUbhUjzBxg/1PThhLtv2wYEdkLpUq1RZmlJACtDD++fkt9x19UecfMpX7NmI43WLoc1x7ydtinrIO0b0NhFStXAPEQXlYyE4JvOSqIxJIbb/E7Vl5okVxOQ==</D></RSAKeyValue>";//my private key
objRsaCrypto.FromXmlString(xmlString);
string cyphertextyear ="mell442PqhwZRDvAVawKhtspVWFsVG6x/6v7BzcaDvOFWImXOiq3hCZq6N0i7UpCkV8YVLLS/LTarWrSgrqskfQnIwA+inZIhfZLm3odUrYpBCMXJh9Y7s+6ugqiwpMu1xap9LBqhP7LdChwIV0c7GimgZKVVk7mZHBgmVOHRSx61RAx6HDkc0F7dfjBR+jUQR08knu4MUUNx7xQ6pSkg1MyTwrX4upMoodccBwni+cUFZWmIeEHazMMd2r6PkuwMvHkueFm0B4UsWnsqHtjgQuU5zmGx9rWpDIyDCKNTvWkTyB1lUrhpNk6qqeFZXVPPTsxfKcA0Pp2oz6ZF4ir";//my cypher text

byte[] bytesCypherText = Convert.FromBase64String(cyphertextyear);
byte[] bytesPlainTextData = objRsaCrypto.Decrypt(bytesCypherText, false);
string strDecryptedVal = Encoding.ASCII.GetString(bytesPlainTextData);

我正在使用 RSACryptoServiceProvider 并且解密在 Windows 8 中工作正常但在 Windows Server 2012 r2 中失败并出现以下异常

System.Security.Cryptography.CryptographicException: Bad Data.

at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey)
at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP)at

最佳答案

您的密文太短。

bytesCypherText 的长度为 255,但您的 2048 位 key 会产生 256 字节的响应。

似乎以前版本的 Windows 接受的太短并且有效地在值前面加上额外的零字节,他们不再这样做了。 (很可能最初的 CAPI 提供者有接受“太短”的行为,但他们已经被调用到驱动 CNG 的同一后端所取代;它可能只接受正确大小的数据。)

如果你的密文base64是

AJnpZeONj6ocGUQ7wFWsCobbKVVhbFRusf+r+wc3Gg7zhViJlzoqt4QmaujdIu1KQpFfGFSy0vy02q1q
0oK6rJH0JyMAPop2SIX2S5t6HVK2KQQjFyYfWO7PuroKosKTLtcWqfSwaoT+y3QocCFdHOxopoGSlVZO
5mRwYJlTh0UsetUQMehw5HNBe3X4wUfo1EEdPJJ7uDFFDce8UOqUpINTMk8K1+LqTKKHXHAcJ4vnFBWV
piHhB2szDHdq+j5LsDLx5LnhZtAeFLFp7Kh7Y4ELlOc5hsfa1qQyMgwijU71pE8gdZVK4aTZOqqnhWV1
Tz07MXynAND6dqM+mReIqw==

你可能会有更好的运气。

或者:

if (bytesCypherText.Length * 8 < objRsaCrypto.KeySize)
{
byte[] tmp = new byte[objRsaCrypto.KeySize / 8];
Buffer.BlockCopy(
bytesCypherText,
0,
tmp,
tmp.Length - bytesCypherText.Length,
bytesCypherText.Length);

bytesCypherText = tmp;
}

byte[] bytesPlainTextData = objRsaCrypto.Decrypt(bytesCypherText, false);

关于c# - 使用 2048 位 key 的 RSA 解密在 Windows Server 2012 r2 上为长度为 340 的加密文本提供了错误数据,而它在 Windows 8 上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43178481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com