-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Govind_k22
Message 1 in Discussion
Hi All,
I want to convert these Java code to .NET using CApicom Interface. I partially
converted.
Java Code:
protected byte[] signpkcs7Data(byte[] dataBytes, PrivateKey prKey, Certificate cer) {
try {
X509Certificate cert = (X509Certificate) cer;
String certificateAlias = cert.getSubjectDN().getName();
Data data = new Data();
data.setData(dataBytes);
ContentInfo contentInfo = new ContentInfo(data);
// Create the SignedData object.
Certificate[] certs = new Certificate[1];
certs[0] = cert;
CRL[] crls = null;
PKCSAttributes signedAttributes = null;
PKCSAttributes unsignedAttributes = null;
PrivateKey[] privateKeys = new PrivateKey[1];
privateKeys[0] = prKey;
boolean signatureOnly = true;
System.out.println("*** Creating the SignedData object and signing the contents.");
System.out.println("This will take a moment...");
SignedData signeddata = new SignedData(certs, crls, contentInfo,
signatureAlgorithm, privateKeys, signedAttributes, unsignedAttributes,
signatureOnly);
SignerInfo signerinfo = signeddata.getSignerInfo(cert);
System.out.println("*** Checking if SignedData/SignerInfo has the certificate.");
if (signeddata.hasCertificate(cert)) {
System.out.println("SUCCESS: SignedData has certificate " + certificateAlias);
} else {
System.out.println("ERROR: SignedData does not have certificate " + certificateAlias);
}
if (signerinfo.hasCertificate(cert)) {
System.out.println("SUCCESS: SignerInfo has certificate "+ certificateAlias);
} else {
System.out.println("ERROR: SignerInfo does not have certificate " + certificateAlias);
}
// Remove the content.
signeddata.removeContent();
ContentInfo cisigneddata = new ContentInfo(signeddata);
return signeddata.encode();
} catch (PKCSException e2) {
System.out.println("\r\nERROR: PKCSException: " + e2);
e2.printStackTrace();
Exception e3 = e2.getRelatedException();
if (e3 != null) {
System.out.println("\r\nOriginal PKCSException stack:");
e3.printStackTrace();
} else {
System.out.println("\r\nNo Original PKCSException stack available");
}
} catch (Exception e) {
System.out.println("\r\nERROR: Exception");
e.printStackTrace();
}
return null;
} .NET codeFunction SignData(ByVal sData As String) As String
Dim sSignedData As String
Dim MyStore As New Store()
Dim Signobj As New SignedData()
Dim Signer As New Signer()
Dim Cert As CAPICOM.Certificate
MyStore.Open(CAPICOM_STORE_LOCATION.CAPICOM_MEMORY_STORE, "MY",
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY)
MyStore.Load("c:\inbnd\cert\test.pfx", "abc2003")
cert = MyStore.Certificates.Item(1)
Signer.Certificate = Cert
Signobj.Content = sData
sSignedData = Signobj.Sign(Signer, False)
Signobj = Nothing
MyStore = Nothing
Signer = Nothing
Return sSignedData
End Function
Regards,
Govind.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]