VBScript
VBScript
Encrypt a JWE with a Password (PBES2)
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.SetPassword, which sets the PBES2 password for a recipient. The example uses PBES2-HS256+A128KW key management with AES-128-GCM content encryption.
Background. PBES2 derives a key-wrapping key from a password using a salt and iteration count, allowing password-based JWE encryption. The password should come from a secure source.
Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
set jwe = CreateObject("Chilkat.Jwe")
' Protected header: PBES2 password-based key management with AES-128-GCM content encryption.
set header = CreateObject("Chilkat.JsonObject")
success = header.UpdateString("alg","PBES2-HS256+A128KW")
success = header.UpdateString("enc","A128GCM")
success = jwe.SetProtectedHeader(header)
If (success = 0) Then
outFile.WriteLine(jwe.LastErrorText)
WScript.Quit
End If
' Set the PBES2 password for recipient 0. The password should come from a secure source rather than
' being hard-coded.
password = "myPassword"
success = jwe.SetPassword(0,password)
If (success = 0) Then
outFile.WriteLine(jwe.LastErrorText)
WScript.Quit
End If
jweCompact = jwe.Encrypt("This is the secret content.","utf-8")
If (jwe.LastMethodSuccess = 0) Then
outFile.WriteLine(jwe.LastErrorText)
WScript.Quit
End If
outFile.WriteLine(jweCompact)
outFile.Close