Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
ASCII / ANSI Secret Key in Symmetric EncryptionUsing an ASCII (or ANSI) secret key w/ symmetric encryption: AES, Blowfish, Twofish, RC2, 3DES, etc.
LOCAL loCrypt LOCAL lnSuccess LOCAL lcEncKey LOCAL lcText LOCAL lcEncText LOCAL lcDecryptedText loCrypt = CreateObject('Chilkat.Crypt2') lnSuccess = loCrypt.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Crypt component unlock failed") QUIT ENDIF * A frequent support question goes something like this: * ------------------ * I am not able to decrypt strings encrypted using * cryptix.jce.provider.key.RawSecretKey (Java) like I would normally do. * The key generation is being done with the Rijndael algorithm (256-bit) * The AES encryption algorithm is "Rijndael/ECB/PKCS#5" * The 32 character source key I'm using is this: * 1234567890123456789012345678912 * * ------------------ * The customer tries to call GenerateSecretKey to * convert the 32-character source key to a binary secret key, * but this is incorrect (in this case). GenerateSecretKey * hashes a string of any length and produces binary hash output * that is of the appropriate size to be used as a secret key. * The telltale sign is that in this case, the string is the exact * length of the secret key. 32 ANSI characters = 256 bits. * Therefore, it is obvious that the bytes of the binary * secret key should be the exact ascii character values * of the string. lcEncKey = "1234567890123456789012345678912" loCrypt.CryptAlgorithm = "aes" * Mode is "ecb" or "cbc" loCrypt.CipherMode = "ecb" loCrypt.KeyLength = 256 * Call SetEncodedKey with "ascii" to tell the component * to use the ascii-bytes as the binary secret key. * Make sure you call this after setting the KeyLength. loCrypt.SetEncodedKey(lcEncKey,"ascii") loCrypt.EncodingMode = "base64" lcText = "The quick brown fox jumped over the lazy dog." * Encrypt a string and return the binary encrypted data * in a base-64 encoded string. lcEncText = loCrypt.EncryptStringENC(lcText) ? lcEncText * Decrypt and show the original string: lcDecryptedText = loCrypt.DecryptStringENC(lcEncText) ? lcDecryptedText |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser