Classic ASP
Classic ASP
JWE using ECDH-ES, BP-256, A256GCM
See more JSON Web Encryption (JWE) Examples
Create a JWE with the following header:
{
"alg": "ECDH-ES",
"enc": "A256GCM",
"exp": 1621957030,
"cty": "NJWT",
"epk": {
"kty": "EC",
"x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"
"y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
"crv": "BP-256"
}
}
Note: This example requires Chilkat v9.5.0.87 or greater.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' This requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
' Load our brainpool BP-256 public key.
' {
' "use": "enc",
' "kid": "puk_idp_enc",
' "kty": "EC",
' "crv": "BP-256",
' "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w",
' "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
' }
set json = Server.CreateObject("Chilkat.JsonObject")
success = json.UpdateString("use","enc")
success = json.UpdateString("kid","puk_idp_enc")
success = json.UpdateString("kty","EC")
success = json.UpdateString("crv","BP-256")
success = json.UpdateString("x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w")
success = json.UpdateString("y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu")
set pubkey = Server.CreateObject("Chilkat.PublicKey")
success = pubkey.LoadFromString(json.Emit())
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pubkey.LastErrorText) & "</pre>"
Response.End
End If
' Build our protected header:
' {
' "alg": "ECDH-ES",
' "enc": "A256GCM",
' "exp": 1621957030,
' "cty": "NJWT",
' "epk": {
' "kty": "EC",
' "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"
' "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
' "crv": "BP-256"
' }
' }
' Use jwt only for getting the current date/time + 3600 seconds.
set jwt = Server.CreateObject("Chilkat.Jwt")
set jweProtHdr = Server.CreateObject("Chilkat.JsonObject")
success = jweProtHdr.UpdateString("alg","ECDH-ES")
success = jweProtHdr.UpdateString("enc","A256GCM")
success = jweProtHdr.UpdateInt("exp",jwt.GenNumericDate(3600))
success = jweProtHdr.UpdateString("cty","NJWT")
success = jweProtHdr.UpdateString("epk.kty","EC")
success = jweProtHdr.UpdateString("epk.x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w")
success = jweProtHdr.UpdateString("epk.y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu")
success = jweProtHdr.UpdateString("epk.crv","BP-256")
set jwe = Server.CreateObject("Chilkat.Jwe")
success = jwe.SetProtectedHeader(jweProtHdr)
success = jwe.SetPublicKey(0,pubkey)
plainText = "This is the text to be encrypted."
strJwe = jwe.Encrypt(plainText,"utf-8")
If (jwe.LastMethodSuccess <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( jwe.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( strJwe) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Success.") & "</pre>"
%>
</body>
</html>