(Classic ASP) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used. Note: This example requires Chilkat v11.0.0 or greater.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
set pubKey = Server.CreateObject("Chilkat.PublicKey")
success = cert.GetPublicKey(pubKey)
set rsa = Server.CreateObject("Chilkat.Rsa")
success = rsa.UsePublicKey(pubKey)
rsa.EncodingMode = "base64"
encryptedStr = rsa.EncryptStringENC("hello",0)
Response.Write "<pre>" & Server.HTMLEncode( "encrypted string = " & encryptedStr) & "</pre>"
%>
</body>
</html>
|