Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
|
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.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-2012 Chilkat Software, Inc. All Rights Reserved.