Click here to Skip to main content
15,900,110 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Usercontrols on Panes Pin
Dave Kreskowiak25-May-04 2:09
mveDave Kreskowiak25-May-04 2:09 
GeneralRe: Usercontrols on Panes Pin
Member 85737725-May-04 8:56
Member 85737725-May-04 8:56 
GeneralRe: Usercontrols on Panes Pin
Dave Kreskowiak25-May-04 11:14
mveDave Kreskowiak25-May-04 11:14 
GeneralRe: Usercontrols on Panes Pin
emari25-May-04 22:02
emari25-May-04 22:02 
GeneralRe: Usercontrols on Panes Pin
Member 85737725-May-04 9:24
Member 85737725-May-04 9:24 
Generalkernel32.dll Call Problems Pin
Pugman81224-May-04 23:03
Pugman81224-May-04 23:03 
GeneralRe: kernel32.dll Call Problems Pin
Dave Kreskowiak25-May-04 0:33
mveDave Kreskowiak25-May-04 0:33 
GeneralRe: kernel32.dll Call Problems Pin
Pugman81225-May-04 9:17
Pugman81225-May-04 9:17 
This is a blowfish cryptography program that i am converting from 6.0 to .NET.
This project has to 2 Textboxs "Textbox1, Textbox2" 2 buttons "btnEncrypt, btnDecrypt" and 1 active X control named VbCryptoEngine1

This program begins when you click the encrypt button
    Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click<br />
<br />
        VbCryptoEngine1.CryptAlgorithm = CryptoEngine.vbCryptoEngine.enuCRYPTO_ALGORITHMS.acuBlowfish<br />
        TextBox2.Text = VbCryptoEngine1.EncryptString(TextBox1.Text, VbCryptoEngine1.key, True)<br />
    End Sub


The VbCryptoEngine1.CryptAlgorithm line works fine it sets a new instance of the class blowfish where all the code for blowfish is contained.

the function EncryptString looks like this

    Public Function EncryptString(ByVal Text As String, Optional ByVal Key As String = "Cool", _<br />
    Optional ByVal OutputInHex As Boolean = False) As String<br />
<br />
        On Error GoTo errhandler<br />
        If m_status = STAT_BUSY Or m_status = STAT_ERROR Then Exit Function<br />
        EncryptString = <font color = "blue">m_Engine</font>.EncryptString(Text, Key, OutputInHex)<br />
        m_status = STAT_READY<br />
        RaiseEvent statuschanged(m_status)<br />
        Exit Function<br />
errhandler:<br />
<br />
        ' ---------------------------------------------------------------------------<br />
        ' Raise friendly error to the handler<br />
        ' ---------------------------------------------------------------------------<br />
        Call Err.Raise(Err.Number, "CryptoEngine:EncryptString", Err.Description)<br />
<br />
    End Function


I was going to us the try catch statement but i will update code later.

the line with the blue sends the string info and a few other variables to the instances blowfish class

The Function looks like this

Public Function EncryptString(ByVal Text As String, Optional ByVal Key As String = "Cool", Optional ByVal OutputInHex As Boolean = False) As String Implements IAlgorithm.EncryptString<br />
        Dim ByteArray() As Byte<br />
<br />
        Dim [unicode] As Encoding = Encoding.Unicode<br />
        Dim ascii As Encoding = Encoding.ASCII<br />
        Dim unicodebytes As Byte()<br />
        Dim asciibytes As Byte()<br />
        m_status = STAT_BUSY<br />
        RaiseEvent statuschanged(m_status)<br />
<br />
        On Error GoTo errhandler<br />
       <font color = "blue">unicodebytes = [unicode].GetBytes(Text)</font><br />
        Encoding.Convert([unicode], Encoding.Default, unicodebytes)<br />
        ByteArray = unicodebytes<br />
        <font color = "Red">Call EncryptByte(ByteArray, Key)</font><br />
        unicodebytes = Encoding.Default.GetBytes(CStr(CObj(ByteArray)))<br />
        Encoding.Convert(Encoding.Default, [unicode], unicodebytes)<br />
        <font color = "blue">EncryptString = CStr(CObj(unicodebytes))</font><br />
        If OutputInHex = True Then EncryptString = EnHex(EncryptString)<br />
        m_status = STAT_READY<br />
        RaiseEvent statuschanged(m_status)<br />
        Exit Function<br />
errhandler:<br />
        m_status = STAT_ERROR<br />
        RaiseEvent statuschanged(m_status)<br />
        ' ---------------------------------------------------------------------------<br />
        ' Raise friendly error to the handler<br />
        ' ---------------------------------------------------------------------------<br />
        Call Err.Raise(Err.Number, Err.Source, Err.Description)<br />
    End Function


Im not cofindent that my conversions are working in the manner that they should but they are not throwing the exception. I need the conversions to do the same thing that the StrConv did to convert from unicode and also to unicode. The lines between the blue are the ones with the converstion. The line in red is what is throwing the exception
The function EncryptByte looks like this

    Public Function EncryptByte(ByVal ByteArray() As Byte, Optional ByVal Key As String = "Cool") As String<br />
<br />
<br />
        Dim Offset As Long, OrigLen As Long, LeftWord As Long, RightWord As Long, CipherLen As Long, CipherLeft As Long, CipherRight As Long, CurrPercent As Long, NextPercent As Long<br />
<br />
        If (Len(Key) > 0) Then Key = Keys<br />
        OrigLen = UBound(ByteArray) + 1<br />
        CipherLen = OrigLen + 12<br />
        If (CipherLen Mod 8 <> 0) Then CipherLen = CipherLen + 8 - (CipherLen Mod 8)<br />
        ReDim Preserve ByteArray(CByte(CipherLen - 1))<br />
<br />
        <font color = "Red">call CopyMemory(CInt(ByteArray(12)), CInt(ByteArray(0)), CInt(OrigLen))</font><br />
        Call CopyMemory(CInt(ByteArray(8)), CInt(OrigLen), 4)<br />
        Call Randomize()<br />
        Call CopyMemory(ByteArray(0), CInt(2147483647 * Rnd()), 4)<br />
        Call CopyMemory(ByteArray(4), CInt(2147483647 * Rnd()), 4)<br />
<br />
        For Offset = 0 To (CipherLen - 1) Step 8<br />
            Call GetWord(CInt(LeftWord), ByteArray, Offset)<br />
            Call GetWord(CInt(RightWord), ByteArray, Offset + 4)<br />
            LeftWord = LeftWord Xor CipherLeft<br />
            RightWord = RightWord Xor CipherRight<br />
            Call EncryptBlock(LeftWord, RightWord)<br />
            Call PutWord(LeftWord, ByteArray, Offset)<br />
            Call PutWord(RightWord, ByteArray, Offset + 4)<br />
            CipherLeft = LeftWord<br />
            CipherRight = RightWord<br />
            If (Offset >= NextPercent) Then<br />
                CurrPercent = CInt((Offset / CipherLen) * 100)<br />
                NextPercent = CInt((CipherLen * ((CurrPercent + 1) / 100)) + 1)<br />
                RaiseEvent Process(CurrPercent)<br />
            End If<br />
            Application.DoEvents()<br />
        Next<br />
<br />
        If (CurrPercent <> 100) Then RaiseEvent Process(100)<br />
        Exit Function<br />
errhandler:<br />
<br />
        ' ---------------------------------------------------------------------------<br />
        ' Raise friendly error to the handler<br />
        ' ---------------------------------------------------------------------------<br />
        Call Err.Raise(Err.Number, Err.Source, Err.Description)<br />
    End Function


The line in red is when it throws the exception back to the function
EncryptString{^} and says that Object reference not set to an instance of an object. The API call is in a public module class along with many public varibles that you do dont see declared. Any help with be appreciated. Just tell me if anyone needs anything else.
GeneralRe: kernel32.dll Call Problems Pin
Dave Kreskowiak25-May-04 11:57
mveDave Kreskowiak25-May-04 11:57 
GeneralRe: kernel32.dll Call Problems Pin
Pugman81225-May-04 12:34
Pugman81225-May-04 12:34 
GeneralOpening large tiff files Pin
NaserAbiat24-May-04 19:22
NaserAbiat24-May-04 19:22 
GeneralRe: Opening large tiff files Pin
Dave Kreskowiak25-May-04 0:30
mveDave Kreskowiak25-May-04 0:30 
GeneralRe: Font color,Type, Columns... Pin
Dave Kreskowiak24-May-04 16:49
mveDave Kreskowiak24-May-04 16:49 
GeneralRe: Font color,Type, Columns... Pin
Dave Kreskowiak25-May-04 0:28
mveDave Kreskowiak25-May-04 0:28 
GeneralRe: Font color,Type, Columns... Pin
rubdub25-May-04 20:18
rubdub25-May-04 20:18 
GeneralSetting Enviroment Variables Pin
waffleman24-May-04 8:58
waffleman24-May-04 8:58 
GeneralRe: Setting Enviroment Variables Pin
Dave Kreskowiak24-May-04 9:22
mveDave Kreskowiak24-May-04 9:22 
GeneralMultithreading Help Pin
800XL24-May-04 5:59
800XL24-May-04 5:59 
GeneralRe: Multithreading Help Pin
Dave Kreskowiak24-May-04 7:11
mveDave Kreskowiak24-May-04 7:11 
GeneralRe: Multithreading Help Pin
800XL24-May-04 23:32
800XL24-May-04 23:32 
GeneralRe: Multithreading Help Pin
Dave Kreskowiak25-May-04 0:24
mveDave Kreskowiak25-May-04 0:24 
GeneralRe: Multithreading Help Pin
800XL25-May-04 0:57
800XL25-May-04 0:57 
GeneralRe: Multithreading Help Pin
800XL26-May-04 1:19
800XL26-May-04 1:19 
QuestionHow can I........? Pin
Night_Soul24-May-04 2:37
Night_Soul24-May-04 2:37 
AnswerRe: How can I........? Pin
Dave Kreskowiak24-May-04 3:22
mveDave Kreskowiak24-May-04 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.