我目前正在尝试创建RSA加密密钥,作为Tableau的Web服务身份验证的一部分。
在加密方面,我是一个菜鸟,并且无法弄清楚如何生成公钥。
我的模数为256字节,指数为5字节。
Imports System.Security.Cryptography
Sub CreateKey()
Dim modulus As String= "bba199e30e41fc23078687dfea032c41bc354518115887f3f59c07ee51628c8d354243d2484a7b7278a2b47e92dd5df7c815ad96b5b59f4e202452b5045587d2eca12fb72aba39bb80048f4a9c83fb1e0187e3d73c323ee35f9437828e5abecb0b894dac45217722eb1d6bbab7ff6661b5f728ca1b0be01f138c6f5f1db5a177"
Dim exponent As String = "10001"
Dim key = New RSAParameters
key.Exponent = Encoding.UTF8.GetBytes(exponent)
key.Modulus = Encoding.UTF8.GetBytes(modulus)
Dim rsa As RSACng = New RSACng()
rsa.ImportParameters(key) 'exception thrown here
End Sub
答案 0 :(得分:1)
您的模数和指数是十六进制编码值。执行Encoding.UTF8.GetBytes(...)
不会进行必要的解码以将字符串转换为正确的模数/指数。
您需要:
Encoding.UTF8.GetBytes(...)
(在StackOverflow和其他地方有很多此类函数的示例)替换:
Dim modulus As String = "bba199..."
使用:
Dim modulus As Byte() = New Byte() { &HBB, &HA1, &H99, ...}