Rijndael

Implementation of the AES Rijndael Block Cipher.  Inspired by Mike Scott’s implementation in C.

License

This is ‘free’ software with the following restrictions

You may not redistribute this code as a ‘sample’ or ‘demo’.  However, you are free to use the source code in your own code, but you may not claim that you created the sample code.  It is expressly forbidden to sell or profit from this source code other than by the knowledge gained or the enhanced value added by your own code.

Use of this software is also done so at your own risk.  The code is supplied as is without warranty or guarantee of any kind.

Should you wish to commission some derivative work based on this code provided here, or any consultancy work, please do not hesitate to contact us.

About

Summary
Implementation of the AES Rijndael Block Cipher.
Use this method to encrypt your data.
Use this method to decrypt your data.
Convert strings into an array of bytes.
Convert an array of bytes into strings.
Convert an array of bytes into it’s hex form.

Functions

encryptData

public function encryptData( bytMessage,
bytPassword )

Use this method to encrypt your data.

Parameters

(string)sMessage Data to be encrypted

Returns

(string) Encrypted version of the input data

Example

dim sMessage : sMessage = "This is a very secret message"
dim sPassword : sPassword = "Password"
 
dim E, byteMessage, bytePassword, encData
set E = new Rijndael
byteMessage  = E.string2bytes(sMessage)
bytePassword = E.string2bytes(sPassword)
encData = E.encryptData( byteMessage, bytePassword )
 
E.gentables
Response.write( "Plain Text: " & sMessage & "<br />" )
Response.write( "Encrypted Hex: " & E.bytes2hex( encData ) & "<br />")
set E = nothing

decryptData

public function decryptData( bytIn,
bytPassword )

Use this method to decrypt your data.

Parameters

(string)sMessage Data to be encrypted

Returns

(string) Encrypted version of the input data

Example

dim sMessage : sMessage = "This is a very secret message"
dim sPassword : sPassword = "Password"
 
dim E, byteMessage, bytePassword, encData
set E = new Rijndael
byteMessage  = E.string2bytes(sMessage)
bytePassword = E.string2bytes(sPassword)
encData = E.encryptData( byteMessage, bytePassword )
 
E.gentables
Response.write( "Plain Text: " & sMessage & "<br />" )
Response.write( "Encrypted Hex: " & E.bytes2hex( encData ) & "<br />")
Response.write( "Decrypted: " &  E.bytes2string( E.decryptData( encData , bytePassword ) ) )
set E = nothing

string2bytes

public function string2bytes( string )

Convert strings into an array of bytes.

Parameters

(string) Word or phrase to be converted

Returns

(bytes) Converted data

Example

Response.write( string2bytes("Lorem ipsum") )

bytes2string

public function bytes2string( bytes )

Convert an array of bytes into strings.

Parameters

(bytes) Byte array to be converted

Returns

(string) Converted data

Example

Response.write( bytes2string( string2bytes("Lorem ipsum") ) )

bytes2hex

public function bytes2hex( bytes )

Convert an array of bytes into it’s hex form.

Parameters

(bytes) Byte array to be converted

Returns

(hex) Converted data

Example

Response.write( bytes2hex( string2bytes("Lorem ipsum") ) )
public function encryptData( bytMessage,
bytPassword )
Use this method to encrypt your data.
public function decryptData( bytIn,
bytPassword )
Use this method to decrypt your data.
public function string2bytes( string )
Convert strings into an array of bytes.
public function bytes2string( bytes )
Convert an array of bytes into strings.
public function bytes2hex( bytes )
Convert an array of bytes into it’s hex form.