Unable to sign data using certficate stored in the smart card

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Unable to sign data using certficate stored in the smart card

chintanvasani
This post has NOT been accepted by the mailing list yet.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); var message = new MimeMessage(); var x = new MultipartSigned(); var body = CreateMessageBody(); using (var ctx = new DefaultSecureMimeContext()) { //var joey = new MailboxAddress("Joey", "joey@friends.com"); AsymmetricAlgorithm x1 = store.Certificates[0].PrivateKey; var key = DotNetUtilities.GetKeyPair(store.Certificates[0].PrivateKey); RSACryptoServiceProvider rs = (RSACryptoServiceProvider)store.Certificates[0].PrivateKey; var f = rs.ExportParameters(false); //AsymmetricKeyParameter x1=new RsaKeyParameters(true,Convert.ToInt64(f.Modulus),f.Exponent); DotNetUtilities.FromX509Certificate(store.Certificates[0]); var certificate = DotNetUtilities.FromX509Certificate(store.Certificates[0]); var signer = new CmsSigner(certificate, key.Private) { DigestAlgorithm = MimeKit.Cryptography.DigestAlgorithm.Sha1 }; x = MultipartSigned.Create(ctx, signer, body); FileStream fs = File.Create(@"c:\index.xml.signed"); x.WriteTo(fs); fs.Close(); } private static TextPart CreateMessageBody() { var body = new TextPart("plain") { Text = File.ReadAllText(@"abc") }; var multipart = new Multipart(); multipart.Add(body); return body; } Here DotNetUtilities.GetKeyPair function gives error as Invalid type specified. This is because the privatekey and certificate is not exportable as this certificate is stored in the smart card and due to security purpose this certficate will never be exportable. Hence please provide some help how to sign the data using private key on the fly using AsymmetricAlgorithm x1 = store.Certificates[0].PrivateKey; or some other method. Please help its really urgent.