Windows Encryption Code not working with Userform

E

ExcelMonkey

Just came across a site at:
http://www.webace.com.au/~balson/InsaneExcel/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
 
T

Tom Ogilvy

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top