Hello All,
I have one trouble with Xceed Encryption library v1.1.
I use the appropriate ActiveX component from both VB6.0 and visual C++ (VS2005) applications. But cypher created by VB application can't be decrypted in vc++ application. Both projects use one ActiveX component but result a different encrypted cyphers. The created cyphers are simply with a different lengths.
Here is my code from VB6.0:
Private Sub Class_Initialize()
Randomize Timer
EMBEDDELIM = Chr$(255)
'--- initialize the XCeed encryption libs
mbySecretKey(1) = &HA
mbySecretKey(2) = &HA
mbySecretKey(3) = &HA
mbySecretKey(4) = &HA
mbySecretKey(5) = &HA
mbySecretKey(6) = &HA
mbySecretKey(7) = &HA
mbySecretKey(8) = &HA
mbySecretKey(9) = &HA
mbySecretKey(10) = &HA
mbySecretKey(11) = &HA
mbySecretKey(12) = &HA
mbySecretKey(13) = &HA
mbySecretKey(14) = &HA
mbySecretKey(15) = &HA
mbySecretKey(16) = &HA
Set mxcEncrypt = New XceedEncryptionLib.XceedEncryption
Set mxcMethod = New XceedEncryptionLib.XceedTwofishEncryptionMethod
'--- License the library for run-time use.
Call mxcEncrypt.License("My license code")
'--- Initialize the encoder.
mxcMethod.EncryptionMode = emoFreeBlocks
mxcMethod.SecretKey = mbySecretKey
mxcMethod.SetInitVectorFromPassPhrase TWOFISHVECTOR
Set mxcEncrypt.EncryptionMethod = mxcMethod
Exit Sub
End Sub
Public Function EncryptStringToHexString(ByVal sSource As String) As String
Dim b() As Byte
Dim bOut() As Byte
Dim lLenIn As Long
Dim lLBound As Long
If (Len(sSource) > 0) Then
soso = Len(sSource)
b() = mxcEncrypt.Encrypt(sSource, True)
lLBound = LBound(b())
lLenIn = UBound(b()) - lLBound + 1
'== !!!!!!!!!!!!!!!!!!!! lLenIn is equal 2064 bytes and Len(sSource) is equal 1024 bytes
End If
Exit Function
End Function
Here is my code in vc++
void CEncryptTesterWithAXDlg::EncryptData(const char* pszSource)
{
CoInitialize( NULL );
try
{
IXceedEncryptionPtr piEnc;
piEnc.CreateInstance( CLSID_XceedEncryption );
piEnc->License( _bstr_t( _T("My license code") ) );
IXceedTwofishEncryptionMethodPtr twoFish;
BYTE mbySecretKey[SECRETKEYLENGTH] = {0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA};
twoFish.CreateInstance( CLSID_XceedTwofishEncryptionMethod );
twoFish->SetSecretKey(mbySecretKey, SECRETKEYLENGTH);
twoFish->EncryptionMode = emoFreeBlocks;
twoFish->SetInitVectorFromPassPhrase(_bstr_t(TWOFISHVECTOR));
piEnc->EncryptionMethod = IXceedEncryptDataPtr( twoFish );
DWORD dwSourceSize = lstrlen( pszSource ) + 1; // Let's say we want to encrypt the null-char too
BYTE* pcEncrypted = NULL;
DWORD dwEncryptedSize = 0;
piEnc->Encrypt( ( BYTE* )pszSource, dwSourceSize, TRUE, &pcEncrypted, &dwEncryptedSize );
'== !!!!!!!!!!!!!!!!!!!! for the same source string dwEncryptedSize is equal only 1040 bytes and Len(sSource) is equal 1024 bytes as well.
CoTaskMemFree( pcEncrypted );
}
catch( const _com_error& xErr )
{
char szMsg[50];
wsprintf( szMsg, "Error %08x\n", xErr.Error() );
}
catch( ... )
{
;//MessageBox( NULL, "Unknown error", "Error", MB_OK );
}
CoUninitialize();
}
Can you explain why Xceed encryption ActiveX works so differently for the different IDE?
I use the same sekret key and initial vectors and algorithm and my goal is to generate the same cyphers from the both VB 6.0 and visual studio 2005 appliactions.