Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old November 18th, 2004, 02:55 AM
naveeng naveeng is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 6 naveeng User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 29 m 53 sec
Reputation Power: 0
Question To Convert Textbox String to Byte Array

in the below code i need to get get the encoded value from textbox and need to convert it to byte array and then decrypt..

how can i do that

  1. Dim xmlKeys As String 'A combination of both the public and
    'private keys
Dim xmlPublicKey As String 'The public key only

'The plaintext message in a byte array
Dim PlainTextBArray As Byte ()
'The cyphertext message in a byte array
Dim CypherTextBArray As Byte ()
<LI>In the Form_Load event, create both the public and private keys: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load 'This creates both the public and the private keys Dim rsa As New RSACryptoServiceProvider 'Hold both keys in a global variable that will be used in the
'decryption procedure
xmlKeys = rsa.ToXmlString(True) 'Hold the public key to be used in the encryption procedure xmlPublicKey = rsa.ToXmlString(False) End Sub<LI>Type in the procedures that encrypt and decrypt, respectively: Private Sub encrypt() Dim rsa As New RSACryptoServiceProvider 'get the public key so you can encrypt the message: rsa.FromXmlString(xmlPublicKey) 'get the message Dim message As String = TextBox1.Text If message.Length > 58 Then MsgBox("You must use fewer than
59 characters") : Exit Sub 'transform message string into a byte array: PlainTextBArray = (New UnicodeEncoding).GetBytes(message) ' Encrypt CypherTextBArray = rsa.Encrypt(PlainTextBArray, False) 'view the cyphertext in TextBox2: TextBox2.Clear() For i As Integer = 0 To CypherTextBArray.Length - 1 TextBox2.Text &= Chr(CypherTextBArray(i)) Next i 'see the lengths of the plaintext, and the cyphertext Me.Text = "Plaintext Length (Unicode): " & PlainTextBArray.Length
& " Cyphertext Length: " & CypherTextBArray.Length End Sub Private Sub decrypt() Dim rsa As New RSACryptoServiceProvider 'get the keys, thereby creating an RSA object that's identical ' to the one used in the Form_Load event when the keys were first built rsa.FromXmlString(xmlKeys) 'create a byte array and then put the decrypted plaintext into it Dim RestoredPlainText As Byte () = rsa.Decrypt(CypherTextBArray, False) 'Step through the two-byte unicode plaintext, displaying the restored
'plaintext message
For i As Integer = 0 To (RestoredPlainText.Length - 1) Step 2 TextBox3.Text &= Chr(RestoredPlainText(i)) Next i End SubTrigger the procedures by button clicks:

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click encrypt() End Sub Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click decrypt() End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > To Convert Textbox String to Byte Array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway