about encrypt and dcrypt of a text
-
hi i want to store a password in the database. for that i m using encrypt and decrypt for this task i written the following code i can perform encrypt but while decrypting i could not get back the actual text please help me ... this is the code i written .... Imports System Imports System.Text Imports System.Security Imports System.Security.Cryptography Imports System.Web.Security Public Class Form1 Dim xmlpublickey As String Dim xmlprivatekey As String Dim plaintextarray() As Byte Dim hpertextarrray() As Byte Dim restoredPlainText() As Byte Dim RSA As New RSACryptoServiceProvider Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load xmlprivatekey = RSA.ToXmlString(True) xmlpublickey = RSA.ToXmlString(False) End Sub Public Sub Encrypt() RSA.FromXmlString(xmlpublickey) Dim msg As String = "" msg = txtoriginal.Text Dim ue As New UnicodeEncoding plaintextarray = ue.GetBytes(msg) hpertextarrray = RSA.Encrypt(plaintextarray, False) txtcypher.Clear() For i As Integer = 0 To hpertextarrray.Length - 1 txtcypher.Text = txtcypher.Text + hpertextarrray(i).ToString() Next End Sub Public Sub Decrypt() RSA.FromXmlString(xmlprivatekey) restoredPlainText = RSA.Decrypt(hpertextarrray, False) txtRestrored.Clear() Dim str As Byte For i As Integer = 0 To restoredPlainText.Length - 1 str = restoredPlainText(i).ToString() txtRestrored.Text += GetChar(str, 1) Next End Sub 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 End Class thanks in advance lavan kumar
-
hi i want to store a password in the database. for that i m using encrypt and decrypt for this task i written the following code i can perform encrypt but while decrypting i could not get back the actual text please help me ... this is the code i written .... Imports System Imports System.Text Imports System.Security Imports System.Security.Cryptography Imports System.Web.Security Public Class Form1 Dim xmlpublickey As String Dim xmlprivatekey As String Dim plaintextarray() As Byte Dim hpertextarrray() As Byte Dim restoredPlainText() As Byte Dim RSA As New RSACryptoServiceProvider Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load xmlprivatekey = RSA.ToXmlString(True) xmlpublickey = RSA.ToXmlString(False) End Sub Public Sub Encrypt() RSA.FromXmlString(xmlpublickey) Dim msg As String = "" msg = txtoriginal.Text Dim ue As New UnicodeEncoding plaintextarray = ue.GetBytes(msg) hpertextarrray = RSA.Encrypt(plaintextarray, False) txtcypher.Clear() For i As Integer = 0 To hpertextarrray.Length - 1 txtcypher.Text = txtcypher.Text + hpertextarrray(i).ToString() Next End Sub Public Sub Decrypt() RSA.FromXmlString(xmlprivatekey) restoredPlainText = RSA.Decrypt(hpertextarrray, False) txtRestrored.Clear() Dim str As Byte For i As Integer = 0 To restoredPlainText.Length - 1 str = restoredPlainText(i).ToString() txtRestrored.Text += GetChar(str, 1) Next End Sub 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 End Class thanks in advance lavan kumar
OK. After taking a look at your code, I'd say scrap it and rewrite it in a more organized fashion, modeling it from this example[^].
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008