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
TwoFish Encrypt to Match Counterpane Test Vectors (ECB Mode)
Visual Basic 6.0 example showing how to encrypt using 128-bit TwoFish encryption to match a test vector published by Counterpane Systems, the inventor of Twofish. '=========================
'
'FILENAME: "ecb_vk.txt"
'
'Electronic Codebook (ECB) Mode
'Variable Key Known Answer Tests
'
'Algorithm Name: TWOFISH
'Principal Submitter: Bruce Schneier, Counterpane Systems
'
'==========
'
'KEYSIZE = 128
'
'PT=00000000000000000000000000000000
'I=1
'key=80000000000000000000000000000000
'CT=6BFD32804A1C3206C4BF85EB11241F89
Private Sub Command10_Click()
Dim crypt As New ChilkatCrypt2
crypt.UnlockComponent "30-day trial"
Dim keyStr As String
Dim clearStr As String
keyStr1 = "80000000000000000000000000000000"
clearStr1 = "00000000000000000000000000000000"
Dim keyBytes As Variant
Dim clearBytes As Variant
' Decode the hex strings to a Variant containing the bytes.
crypt.CryptAlgorithm = "none"
crypt.EncodingMode = "hex"
keyBytes = crypt.DecryptBytesENC(keyStr1)
clearBytes = crypt.DecryptBytesENC(clearStr1)
crypt.CryptAlgorithm = "twofish"
crypt.CipherMode = "ecb"
crypt.KeyLength = 128
crypt.SecretKey = keyBytes
cipherStr = crypt.EncryptBytesENC(clearBytes)
' The Chilkat component pads to a multiple of 16 bytes.
' The default padding scheme is to pad with a byte value
' equaling the number of padding bytes. If the input
' is an exact multiple of 16 bytes, as in this case,
' an extra 16 bytes of padding (padding byte = 0x10) is
' added.
'
' Given that each byte is represented by 2 characters,
' we keep the 1st 32 characters of the output string
' to match the test vector exactly:
cipherStr = Left$(cipherStr, 32)
MsgBox cipherStr
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.