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")
CryptutBuffer = ""
Crypto.InBuffer = .TextBoxes("PlainText").Text
Crypto.Encrypt
.TextBoxes("Encrypted").Text = CryptutBuffer
'.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 = CryptutBuffer
'.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")
CryptutBuffer = ""
Crypto.InBuffer = MainForm.PlainTextBox.Text 'Took
out.TextBoxes("PlainText").Text
Crypto.Encrypt
MainForm.EncryptedBox.Text = CryptutBuffer '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 = CryptutBuffer 'Took out
..TextBoxes("PlainText").Text
End Sub
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")
CryptutBuffer = ""
Crypto.InBuffer = .TextBoxes("PlainText").Text
Crypto.Encrypt
.TextBoxes("Encrypted").Text = CryptutBuffer
'.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 = CryptutBuffer
'.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")
CryptutBuffer = ""
Crypto.InBuffer = MainForm.PlainTextBox.Text 'Took
out.TextBoxes("PlainText").Text
Crypto.Encrypt
MainForm.EncryptedBox.Text = CryptutBuffer '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 = CryptutBuffer 'Took out
..TextBoxes("PlainText").Text
End Sub