3
SignedXML 클래스를 사용하여 rsa-sha256 xml 서명을 수행하고 있습니다. 그러나 문제는 sha256을 지원하기 위해 CSP를 변경해야한다는 것입니다. 내가 인증서를 선택하고 어떻게 이것은RSACryptoServiceProvider의 CSP 매개 변수를 변경하는 방법
는,
public X509Certificate2 GetCertificateFromStore()
{
X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser);
st.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = st.Certificates.Find(X509FindType.FindByTimeValid, (object)DateTime.Now, false);
X509Certificate2 x509Certificate =null;
X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(col, "Certificate", "Select single certificate to sign", X509SelectionFlag.SingleSelection);
if (sel.Count > 0)
{
X509Certificate2Enumerator en = sel.GetEnumerator();
en.MoveNext();
x509Certificate = en.Current;
}
st.Close();
//x509Certificate.s
return x509Certificate;
}
이것은 내가 CSP 매개 변수를 변경하려고하는 방법이다.
byte[] privateKeyBlob;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa = cert.PrivateKey as RSACryptoServiceProvider;
try
{
privateKeyBlob = rsa.ExportCspBlob(true);
}
catch
{
throw new ApplicationException("Private key fails to export");
}
// To use the RSA-SHA256 the CryptoAPI needs to select a special CSP: Microsoft Enhanced RSA and AES Cryptographic Provider
// By reinstantiating a CSP of type 24 we ensure that we get the right CSP.
CspParameters cp = new CspParameters(24);
rsa = new RSACryptoServiceProvider(cp);
rsa.ImportCspBlob(privateKeyBlob);
signer.SigningKey = rsa;
signer.KeyInfo = getKeyInfo(signer, cert);
문제점 USB 장치 토큰을 사용하고 있는데 개인 키를 내보낼 수없는 것으로 의심됩니다. 내보내는 중에 '키가 지정된 상태에서 사용하기에 유효하지 않습니다. '.
아무도 도움을 줄 수 있습니까?
어떤 줄이 예외입니까? – craig1231
이 줄 privateKeyBlob = rsa.ExportCspBlob (true); – Matt
http://stackoverflow.com/q/10673146/589259 도움이 되셨습니까? –