Sample code for 30+ languages & platforms
Classic ASP

Decrypt a JWE with a Private Key

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.SetPrivateKey, which sets the private key used to decrypt a recipient of a loaded JWE.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. The private key unwraps the content-encryption key that was wrapped with the corresponding public key during encryption.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

set jwe = Server.CreateObject("Chilkat.Jwe")

'  Load the JWE compact serialization to be decrypted.
jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
success = jwe.LoadJwe(jweCompact)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( jwe.LastErrorText) & "</pre>"
    Response.End
End If

'  The file path is relative to the application's current working directory.  An absolute path
'  may also be used.  Supply the path appropriate to your own environment.
'  Load the recipient's private key.
set privKey = Server.CreateObject("Chilkat.PrivateKey")
success = privKey.LoadPemFile("qa_data/recipient_privkey.pem")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( privKey.LastErrorText) & "</pre>"
    Response.End
End If

'  Set the private key used to decrypt recipient 0.
success = jwe.SetPrivateKey(0,privKey)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( jwe.LastErrorText) & "</pre>"
    Response.End
End If

content = jwe.Decrypt(0,"utf-8")
If (jwe.LastMethodSuccess = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( jwe.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( content) & "</pre>"

%>
</body>
</html>