Cast 128 ActiveX component v1.2A simple ActiveX component who allows to encrypt/decrypt data through
the Cast128 algorithm. He acts also as fast base64 codec and converter
from string to Array and viceversa. This document has been translate quickly from Italian to english using
http://www.systransoft.com/. If you found errors (above all in the code),
please write me about it. (C) & Disclaimer | ||||||||||||||||||||||||||||||||||||
| The implementation of Cast128 has been made outside of the USA | ||||||||||||||||||||||||||||||||||||
|
What's new in this version: Added compatibility with ASP method Response.BinaryWrite of the output
of Array type ( cast128ArrayEnc, cast128ArrayDec,
b64ArrayEnc ) Index0. Known Bugs
3. Example of Use
1. InstallationIn order to install this component: 1) Copy the cast.dll file in a system folder (c:\windows or c:\winnt
or c:\winnt\system32 or similar) For uninstall the component: 1) There isn't a " clean way " to do it. 2. Documentation | ||||||||||||||||||||||||||||||||||||
|
The component uses Cast128 as encryption algorithm. Cast is an algorithm
of "symmetrical" type, and therefore is necessary to use the same key
in order to encrypt and decrypt data. The component has been created originally in order encrypt important
data sent through cookies (like login and password). In order to create an instance of cipher, you can use the symbolic
reference "cast.cipher" or CLSID { 12BBFB97-0aec-4837-8061-12ca8ead166b
} In order to create an instance in VisualBasic/VBScript: In ASP: The cipher interface implements that methods: 1) VARIANT cast128encode(VARIANT
key, VARIANT inString)
VARIANT cast128encode(VARIANT key, VARIANT inString) Encrypt a string using the key specified in key. It gives return a base64 string. Use cast128ArrayEnc if you want to encrypt an Array. Parameters:
Returned Value: The string returned is contained in a VARIANT.
VARIANT cast128decode(VARIANT key, VARIANT inBase64String) It decrypts a string generated previously from cast128encode(), using the key specified in key. It gives back a string representing the original data. If you want to decrypt an Array it uses cast128ArrayDec Parameters:
Returned Value:
VARIANT cast128ArrayEnc(VARIANT key, VARIANT inArray) Encrypt an array using the key specified in key. It gives back an Array of bytes containing the encrypted data. If you want Encrypt strings, use cast128encode Parameters:
Returned Value:
VARIANT cast128ArrayDec(VARIANT key, VARIANT inArray) It decrypts an Array of byte previously encrypted using cast 128 and using the key specified in key. It return an Array containing the original data. If you want to decrypt strings, use cast128decode. Parameters:
Returned Value:
VARIANT b64StrEnc(VARIANT inString) It codifies a string using base64. The output it is a base64 string. If you want to codify Array, use b64ArrayEnc Parameters:
Returned Value:
VARIANT b64StrDec(VARIANT inBase64String) It decodes one tightens codified in base64. De you want to decodifcare attay uses b64ArrayDec Parameters:
Returned Value:
VARIANT b64ArrayEnc(VARIANT inArray) It codifies an Array of bytes using base64. The output it is a base64
string. Parameters:
Returned Value:
VARIANT b64ArrayDec(VARIANT inBase64String) It decodes a base64 string and places decoded data in an Array of bytes (unsigned 8 bit). If you want a string as output use b64StrDec. Parameters:
Returned Value:
VARIANT encode (VARIANT key, VARIANT inString) A alias of cast128encode
A alias of cast128decode
InData VARIANT toBArray(VARIANT) It converts a string to an Array of bytes. Such Array is usable with the other methods of the cipher class (ex. with b64ArrayEnc ) and with the ASP method Response.BinaryWrite. If you want to convert an Array to a string, use the method toString. Parameters:
It gives back:
VARIANT toString(VARIANT inArray) It converts an Array of integer value in a string. If you want to convert
a string to an Array of Bytes use the method toBArray Parameters:
It gives back: 3. Examples of useCast Encrypt/Decrypt of a string in Visual Basic:
Set ObjCast = CreateObject("cast.cipher")
Dim tkey As Variant
Dim original As Variant
Dim encodedText As Variant
Dim decodedText As Variant
tkey = "the Key"
original = "Encoded Text"
encodedText = ObjCast.cast128encode(tkey, original)
decodedText = ObjCast.cast128decode(tkey, encodedText)
msgbox("Dati originali:" & original & vbNewline & "Dati criptati: " & encodedText & vbNewline & _
"Dati decriptati: " & decodedText)
Set ObjCast = Nothing
Cookies with ASP VBScript: Setting of an encrypted cookie
set objCast128 = server.createObject("cast.cipher")
response.cookies("CookieName")("server") = objCast128.cast128encode("pass", "www.anon.net" )
response.cookies("CookieName")("login") = objCast128.cast128encode("pass", "myname")
response.cookies("CookieName")("password") = objCast128.cast128encode("pass","mypassword")
Response.Cookies("CookieName").Expires = dateadd("d",10,date)
Response.Cookies("maiCookieNamelclient").Domain = "www.anon.net"
Response.Cookies("CookieName").Path = "/"
Response.Cookies("CookieName").Secure = false
Getting an encrypted cookie
set objCast128 = server.createObject("cast.cipher")
encodedLogin = request.cookies("CookieName")("login")
encodedPassword = request.cookies("CookieName")("password")
encodedServer = request.cookies("CookieName")("server")
Login = objCast128.cast128decode("pass", encodedLogin )
Password = objCast128.cast128decode("pass", encodedPassword )
MyServer = objCast128.cast128decode("pass", encodedServer )
Base64 encoding/decoding of an array in ASP VBScript:
set objCast128 = server.createObject("cast.cipher")
OriginalArray = Array(1, 3, 90, 23, 66, 3)
strB64EncodedArray = objCast128.b64ArrayEnc(OriginalArray)
DecodedArray = objCast128.b64ArrayDec(strB64EncodedArray)
response.write("Dati originali: " & OriginalArray(0) & ", " & OriginalArray(1) & _
", " & OriginalArray(2) & ", " & OriginalArray(3) & ", " & OriginalArray(4) & _
", " & OriginalArray(5) & )
response.write("dati codificati in Base64: " strB64EncodedArray & )
response.write("dati decodificati: " & DecodedArray(0) & ", " & DecodedArray(1) & _
", " & DecodedArray(2) & ", " & DecodedArray(3) & ", " & DecodedArray(4) & _
", " & DecodedArray(5) & )
Cast encrypt/decrypt of an array in ASP VBScript:
set objCast128 = server.createObject("cast.cipher")
OriginalArray = Array(1, 3, 90, 23, 66, 3)
Key = "the Key"
Cast128EncryptedArray = objCast128.cast128ArrayEnc(Key,OriginalArray)
DecryptedArray = objCast128.b64ArrayDec(key, Cast128EncryptedArray)
response.write("dati originali: " & OriginalArray(0) & ", " & OriginalArray(1) & _
", " & OriginalArray(2) & ", " & OriginalArray(3) & ", " & OriginalArray(4) & _
", " & OriginalArray(5) )
response.write("dati criptati: " & Cast128EncryptedArray(0) & ", " & Cast128EncryptedArray(1) & _
", " & Cast128EncryptedArray(2) & ", " & Cast128EncryptedArray(3) & ", " & _
Cast128EncryptedArray(4) & ", " & Cast128EncryptedArray(5) )
response.write("dati decriptati: " & DecryptedArray(0) & ", " & DecryptedArray(1) & _
", " & DecryptedArray(2) & ", " & DecryptedArray(3) & _
", " & DecryptedArray(4) & ", " & DecryptedArray(5))
4. History
5. Structure of the cast128encode outputThe cast128encode method transforms input string in an Array of unsigned char. After that it codifies this Array using base64. If the obtained string have an uneven number of blocks of 4 byte (or base64 blocks), 4 characters of ' = ' are added to the end of the string. That assures that the string contains a multiple number of elements of 8. That String is encrypted with the cast128 algorithm. The output it comes newly codified in base64 in order obtaining an ASCII string. The output generated is large approximately 50% in more than the input. In the next version I will take care to change the algorithm to lower the space occupied by the output, maintaining in any case a compatibility with old versions.
|