Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

AES Encrypt Byte Array

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

ASP script to AES encrypt a byte array.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set crypt = Server.CreateObject("Chilkat_9_5_0.Crypt2")

' Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    Response.Write "Crypt component unlock failed" & "<br>"

End If

' Use 128-bit AES encryption, in CBC mode.
crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "cbc"
crypt.KeyLength = 128

' Create a byte array for our secret key and
' initialization vector:
' this byte array has 16 bytes (i.e. 128 bits)
Dim key
For i = 0 To 15
key = key & ChrB(i)
Next

Dim iv
For i = 0 To 15
iv = iv & ChrB(i)
Next

' Create a byte array to be encrypted.
Dim data
For i = 0 To 255
data = data & ChrB(i)
Next

crypt.SecretKey = key
crypt.IV = iv

Dim encryptedBytes
encryptedBytes = crypt.EncryptBytes(data)

' How many bytes in the encrypted output?
Response.Write "<p>Encrypted output size = " & (UBound(encryptedBytes)+1) & "</p>"

' We encrypted 256 bytes and the output is 272 bytes.  Why?
' That's because padding is required to maintain a 16-octet (128-bit) blocksize. 

' The IV is always equal to the blocksize in any symmetric
' encryption algorithm.
' PKCS#5 padding works as follows: the bytes remaining to fill a
' block are assigned a number, which is the number of bytes that
' were added to fill the block. For instance, if we have an 16-byte
' block, and only 11 bytes are filled, then we have 5 bytes to pad.
' Those 5 bytes are all assigned the value "5", for the 5 bytes of
' padding.  In the case where the data is already a multiple
' of 16, an additional 16 bytes are added, each byte containing 0x10.
' Thus, when 256 bytes are encrypted, the result is 272 bytes.


' Display the encrypted bytes in hex:
Response.Write "<p>" & crypt.Encode(encryptedBytes,"hex") & "</p>"   
' Display the encrypted bytes as decimal integers:
Dim s
s = ""
For i = 1 To LenB(encryptedBytes)
    s = s & CStr(AscB(MidB(encryptedBytes, i, 1))) & ","
Next
Response.Write "<p>" & s & "</p>"

' Decrypt the data and show the decrypted data in hex:
Dim decryptedBytes
decryptedBytes = crypt.DecryptBytes(encryptedBytes)

' How many bytes in the decrypted output?
Response.Write "<p>Decrypted output size = " & (UBound(decryptedBytes)+1) & "</p>"

' Display the decrypted bytes in hex:
Response.Write "<p>" & crypt.Encode(decryptedBytes,"hex") & "</p>"   
' Display the decrypted bytes as decimal integers:
s = ""
For i = 1 To LenB(decryptedBytes)
    s = s & CStr(AscB(MidB(decryptedBytes, i, 1))) & ","
Next
Response.Write "<p>" & s & "</p>"

%>
</body>
</html>

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.