![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
AES Encrypt a File to a Base64 String
Loads a file into memory and encrypts using 256-bit AES encryption and returns the result as a base64 string (i.e. the binary encrypted data is encoded to base-64). <html>
<body>
<%
set crypt = CreateObject("Chilkat_9_5_0.Crypt2")
unlocked = crypt.UnlockComponent("Anything for 30-day trial")
' Use Chilkat Crypt's ReadFile method to load the entire contents
' of a file into a Variant (containing a byte array).
gifImageData = crypt.ReadFile(Server.MapPath("images/orval.gif"))
' Our secret key (in this example) is a 32-byte (256-bit) key
' already encoded in Base64. We need to decode it to get the binary
' secret key:
crypt.CryptAlgorithm = "none"
crypt.EncodingMode = "base64"
keyStr = "dIDJu7fzCnwVpOX9yfXsPg=="
binaryKey = crypt.DecryptBytesEnc(keyStr)
' Now encrypt the GIF image data.
' We want 256-bit AES encryption. (Why 256-bit? Because our secret
' key is 256-bits long. The length of the secret key must match the
' KeyLength
crypt.KeyLength = 256
crypt.SecretKey = binaryKey
crypt.CryptAlgorithm = "AES"
' We want the output to be a string containing the base64-encoding of the
' encrypted data.
crypt.EncodingMode = "base64"
' EncryptBytesEnc accepts bytes (a Variant) and returns an encoded string.
encryptedDataStr = crypt.EncryptBytesEnc(gifImageData)
Response.Write "<p>Base64: " + encryptedDataStr + "</p>"
%>
</body>
</html>
|
|||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.