+ Reply to Thread
Results 1 to 2 of 2

Windows Encryption Code not working with Userform

  1. #1
    ExcelMonkey
    Guest

    Windows Encryption Code not working with Userform

    Just came across a site at:
    http://www.webace.com.au/~balson/Ins...Encryption.htm

    which show an example of Microsofts Cryto API. I thought it was interesting
    and wanted to look at it as I had never seen the code for this. Effectivel
    the author has three inputs which feed the code:

    1) Public Key (Cell input)
    2) Plain Text (textbox in sheet)
    3) Encrypted Text (textbox in sheet)

    The idea being that you punch public key into the first input, input plain
    text into the second input, and then encrypt the plain text. Alternatively,
    you can decrypt the encrypted text with the same public key.

    The author does not use a userform for the inputs. I wanted to attach a
    simple userform to the code and see if I could make it work. However I
    cannot seem to get it to work with the userform. The original code for
    passing the three inputs looks like this (have not included the
    functions/subs):

    '**********************************************************
    Sub EncryptMessage()

    With Sheets("Text")
    Crypto.Password = Range("Password")
    Crypto.OutBuffer = ""
    Crypto.InBuffer = .TextBoxes("PlainText").Text
    Crypto.Encrypt
    .TextBoxes("Encrypted").Text = Crypto.OutBuffer
    '.TextBoxes("PlainText").Text = ""
    End With
    End Sub

    Sub DecryptMessage()
    With Sheets("Text")
    Crypto.Password = Range("Password")
    Crypto.InBuffer = .TextBoxes("Encrypted").Text
    Crypto.Decrypt
    .TextBoxes("PlainText").Text = Crypto.OutBuffer
    '.TextBoxes("Encrypted").Text = ""
    End With
    End Sub
    '*********************************************************
    As I am simply using a userform with three textboxes to replace the cell
    range and two text boxes in the spreadsheet, I displayed the userform afte
    the Workbook_Open Event, and passed variables from the

    Private Sub Workbook_Open()
    Dim X As Double
    MainForm.Show
    End Sub

    However the code does not seem to work if I type in a phrase that is over 10
    characters long. This does work in the original version. I am just
    wondering if its the fact that I am using text boxes. Do I need to covert to
    a different data type? The code seems to take string values. Can't figure
    out why this is not working. My changes with userform are below.

    Thanks

    '**********************************************************
    Sub EncryptMessage()

    Crypto.Password = MainForm.PassPhraseBox.Text 'Took out Range("Password")
    Crypto.OutBuffer = ""
    Crypto.InBuffer = MainForm.PlainTextBox.Text 'Took
    out.TextBoxes("PlainText").Text
    Crypto.Encrypt
    MainForm.EncryptedBox.Text = Crypto.OutBuffer 'Took out
    ..TextBoxes("Encrypted").Text
    End Sub

    Sub DecryptMessage()
    Crypto.Password = MainForm.PassPhraseBox.Text 'Took out Range("Password")
    Crypto.InBuffer = MainForm.EncryptedBox.Text 'Took out
    ..TextBoxes("Encrypted").Text
    Crypto.Decrypt
    MainForm.PlainTextBox.Text = Crypto.OutBuffer 'Took out
    ..TextBoxes("PlainText").Text
    End Sub



  2. #2
    Tom Ogilvy
    Guest

    Re: Windows Encryption Code not working with Userform

    The code worked fine for me. I made the code you show the click events for
    commandbuttons on the userform.


    Did you set the multiline property of the textboxes to true?
    --
    Regards,
    Tom Ogilvy


    "ExcelMonkey" <[email protected]> wrote in message
    news:[email protected]...
    > Just came across a site at:
    > http://www.webace.com.au/~balson/Ins...Encryption.htm
    >
    > which show an example of Microsofts Cryto API. I thought it was

    interesting
    > and wanted to look at it as I had never seen the code for this.

    Effectivel
    > the author has three inputs which feed the code:
    >
    > 1) Public Key (Cell input)
    > 2) Plain Text (textbox in sheet)
    > 3) Encrypted Text (textbox in sheet)
    >
    > The idea being that you punch public key into the first input, input plain
    > text into the second input, and then encrypt the plain text.

    Alternatively,
    > you can decrypt the encrypted text with the same public key.
    >
    > The author does not use a userform for the inputs. I wanted to attach a
    > simple userform to the code and see if I could make it work. However I
    > cannot seem to get it to work with the userform. The original code for
    > passing the three inputs looks like this (have not included the
    > functions/subs):
    >
    > '**********************************************************
    > Sub EncryptMessage()
    >
    > With Sheets("Text")
    > Crypto.Password = Range("Password")
    > Crypto.OutBuffer = ""
    > Crypto.InBuffer = .TextBoxes("PlainText").Text
    > Crypto.Encrypt
    > .TextBoxes("Encrypted").Text = Crypto.OutBuffer
    > '.TextBoxes("PlainText").Text = ""
    > End With
    > End Sub
    >
    > Sub DecryptMessage()
    > With Sheets("Text")
    > Crypto.Password = Range("Password")
    > Crypto.InBuffer = .TextBoxes("Encrypted").Text
    > Crypto.Decrypt
    > .TextBoxes("PlainText").Text = Crypto.OutBuffer
    > '.TextBoxes("Encrypted").Text = ""
    > End With
    > End Sub
    > '*********************************************************
    > As I am simply using a userform with three textboxes to replace the cell
    > range and two text boxes in the spreadsheet, I displayed the userform afte
    > the Workbook_Open Event, and passed variables from the
    >
    > Private Sub Workbook_Open()
    > Dim X As Double
    > MainForm.Show
    > End Sub
    >
    > However the code does not seem to work if I type in a phrase that is over

    10
    > characters long. This does work in the original version. I am just
    > wondering if its the fact that I am using text boxes. Do I need to covert

    to
    > a different data type? The code seems to take string values. Can't

    figure
    > out why this is not working. My changes with userform are below.
    >
    > Thanks
    >
    > '**********************************************************
    > Sub EncryptMessage()
    >
    > Crypto.Password = MainForm.PassPhraseBox.Text 'Took out

    Range("Password")
    > Crypto.OutBuffer = ""
    > Crypto.InBuffer = MainForm.PlainTextBox.Text 'Took
    > out.TextBoxes("PlainText").Text
    > Crypto.Encrypt
    > MainForm.EncryptedBox.Text = Crypto.OutBuffer 'Took out
    > .TextBoxes("Encrypted").Text
    > End Sub
    >
    > Sub DecryptMessage()
    > Crypto.Password = MainForm.PassPhraseBox.Text 'Took out

    Range("Password")
    > Crypto.InBuffer = MainForm.EncryptedBox.Text 'Took out
    > .TextBoxes("Encrypted").Text
    > Crypto.Decrypt
    > MainForm.PlainTextBox.Text = Crypto.OutBuffer 'Took out
    > .TextBoxes("PlainText").Text
    > End Sub
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1