Use CAPICOM in Server Side

I have a code in .net for sign in client side and verify in server side.

And I must convert my code in asp classic.

In .net code on client side I sign with capicom by javascript.

My code:

<script type="text/javascript">
// Some needed constants
CAPICOM_CURRENT_USER_STORE = 2;
CAPICOM_STORE_OPEN_READ_ONLY = 0;
CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME = 0;
CAPICOM_ENCODE_BASE64 = 0;
function Authenticate() {
try {
var challenge = document.getElementById("<%=hid_Challenge.ClientID %>");
var response = document.getElementById("<%=hid_Response.ClientID %>");

// Open windows certificate store
var store = new ActiveXObject("CAPICOM.Store");
store.Open(CAPICOM_CURRENT_USER_STORE, "My", CAPICOM_STORE_OPEN_READ_ONLY);

// Show personal certificates which are installed for this user
var certificates = store.Certificates.Select("KeyA3 Sample PKI Authentication", "Please select a certificate to authenticate.");

// Proceed if any certificate is selected
if (certificates.Count > 0) {
var signer = new ActiveXObject("CAPICOM.Signer");
signer.Certificate = certificates.Item(1);

var timeAttrib = new ActiveXObject("CAPICOM.Attribute");
timeAttrib.Name = CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME;
var date = new Date('<%=DateTime.Now.ToString("F", new System.Globalization.CultureInfo("en-US")) %>');
timeAttrib.Value = date.getVarDate();
signer.AuthenticatedAttributes.Add(timeAttrib);

var signedData = new ActiveXObject("CAPICOM.SignedData");
signedData.Content = challenge.value;
response.value = signedData.Sign(signer, true, CAPICOM_ENCODE_BASE64);

return true;
}
return false;
}
catch (e) {
alert(e.description);
return false;
}
}
</script>

And

I check signed data in this code:

Byte[] signedData;
ContentInfo content;
SignedCms signed;

if (hid_Response.Value == null)
throw new ArgumentNullException("Response");

signedData = Encoding.Unicode.GetBytes(Session["Challenge"].ToString());
content = new ContentInfo(signedData);

signed = new SignedCms(content, true);
signed.Decode(Convert.FromBase64String(hid_Response.Value));

// Set the parameter to 'true' if you want the certificate not be checked. 
signed.CheckSignature(true);

// Do further authentication and user mapping here.
// For example you could check some certificate parameters against your database.
// Here we only show the certificate information. Nothing checked here.
lbl_Message1.Text = "Authenticated successfully.";
lbl_Message1.Visible = true;

Dictionary<String, String> certProps = new Dictionary<String, String>();
certProps.Add("Subject", signed.Certificates[0].Subject);
certProps.Add("Issuer", signed.Certificates[0].Issuer);
certProps.Add("Valid From", signed.Certificates[0].NotBefore.ToString());
certProps.Add("Valid To", signed.Certificates[0].NotAfter.ToString());
certProps.Add("Friendly Name", signed.Certificates[0].FriendlyName);
certProps.Add("Version", signed.Certificates[0].Version.ToString());
certProps.Add("Serial Number", signed.Certificates[0].SerialNumber);
certProps.Add("Thumbprint", signed.Certificates[0].Thumbprint);
gvCertificate.DataSource = certProps;
gvCertificate.DataBind();
gvCertificate.Visible = true;

But I must run this code in asp classic

I successfully sign my data in client side by javascript.

And I want to verify data in server side by VBSCRIPT OR JAVASCRIPT.

Is any way?

Thanks

Answers


I found answer.

It will be helpful.

Dim verification
Set verification = Server.CreateObject("CAPICOM.SignedData")
verification.Verify signed_Data, false, 0
For Each Certificate In verification.Certificates
    subject = Certificate.SubjectName
Next
If Err.Number <> 0 Then
    result =  Err.Description &  Hex(Err.Number)
Else
    result = "Signature is OK"
End If

Need Your Help

Ajax Post doesnt work the first time but it works the second

php jquery ajax

I already asked this once, but now I cant fixed it the same way. I have a smartwizard page and when I click finish I want to call a php function throught ajax and get the response from the server.

Spark DataFrames: registerTempTable vs not

apache-spark dataframe

I just started with DataFrame yesterday and am really liking it so far.