2
我不能得到签名验证工作,就像它描述的here。我正在使用BouncyCastle.NetCore 1.8.1.3,该项目是一个.NETCoreApp 1.0。Alexa技能签名验证失败
我在macOS 10.12.1上开发,运行dotnet核心1.0.4,我的服务器运行Ubuntu 16.04.2-x64运行发行版,构建为netcore1.0和ubuntu16.04-x64应用程序。
除签名验证外,系统的其余部分运行时没有问题。
我的验证总是返回false。
这里是我的验证签名和身体服务:
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace MySkill.Main.Services
{
public class CertificationValidationService : ICertificationValidationService
{
private const string Algorithm = "SHA1withRSA";
public async Task<bool> IsValidSiganture(Stream body, Stream certData, string signature)
{
var pemReader = new Org.BouncyCastle.OpenSsl.PemReader(new StreamReader(certData));
var cert = (Org.BouncyCastle.X509.X509Certificate)pemReader.ReadObject();
using (var sr = new StreamReader(body))
{
var content = await sr.ReadToEndAsync();
var result = CheckRequestSignature(Encoding.UTF8.GetBytes(content), signature, cert);
return result;
}
}
private static bool CheckRequestSignature(byte[] bodyData, string signature, Org.BouncyCastle.X509.X509Certificate cert)
{
byte[] sig = Convert.FromBase64String(signature);
var pubKey = (Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters)cert.GetPublicKey();
var signer = Org.BouncyCastle.Security.SignerUtilities.GetSigner(Algorithm);
signer.Init(false, pubKey);
signer.BlockUpdate(bodyData, 0, bodyData.Length);
return signer.VerifySignature(sig);
}
}
}
没有任何人有一个提示,我在做什么错误或者已经使用了不同的框架或API?
1.您确定使用UTF8编码的“内容”? 2.你有没有尝试一种不同的算法? – ChrisM
1.是的,内容确实是UTF8。 2.我尝试了System.Security.Cryptography.X509Certificates类。但它也不起作用。它正在崩溃dotnet。 – Duglah