Home Forums ActiveX components Xceed Encryption for ActiveX I can’t decrypt cipher created ny another application

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #42982 |

    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 );

          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;

          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 );


    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.

    Imported from legacy forums. Posted by Dereak (had 4170 views)

    User (Old forums)
    Post count: 23064

    If you are testing this with a string, both will not produce the same result, since in C++ a string is ANSI, whereas in VB it is Unicode.  Make sure to use the same encoding, or test this with binary data, and it should work fine.

    Imported from legacy forums. Posted by André (had 405 views)

    User (Old forums)
    Post count: 23064

    I see. Thank you.

    In c++ I use this way for the data encryption:

            LPOLESTR wsz;
            AnsiToUnicode(pszSource, &wsz);
            dwSourceSize = lstrlenW( wsz );

            BYTE* pcEncrypted = NULL;
            DWORD dwEncryptedSize = 0; 

            m_xceedEncryption->Encrypt( (BYTE*)wsz, 2 * dwSourceSize, TRUE, &pcEncrypted, &dwEncryptedSize );  

    And this way for decrypting data:

            LPCOLESTR pcDecrypted = NULL;
            DWORD dwDecryptedSize = 0; 

            m_xceedEncryption->Decrypt( sourceUnprotected, unprotectedSourceLen, TRUE, (BYTE**)&pcDecrypted, &dwDecryptedSize );

            LPSTR pcDecryptedStr = NULL;
            UnicodeToAnsi(pcDecrypted, &pcDecryptedStr);

    Imported from legacy forums. Posted by Dereak (had 5607 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.