RSA Encryption - Bad Length Error

From: Wayne P. (infinite@nospam-totalink.net)
Date: 03/23/03


From: "Wayne P." <infinite@nospam-totalink.net>
Date: Sun, 23 Mar 2003 10:56:30 -0500


I am playing around with RSA to learn about it with the end goal of creating
a Licensing solution for an application. This is code from my sample 'Play'
applicaiton.

Everything works great until the line:
Dim CryptData() As Byte = rsa.Encrypt(toCrypt, True)

I get a Bad Length Error - Any insight would be helpful. Thanks - see my
code below....

Private Sub btnEncryptData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEncryptData.Click

Dim rsa As RSACryptoServiceProvider = New RSACryptoServiceProvider(1024)

rsa.FromXmlString(strPrivateKey)

Dim fIn As New FileStream("emp.xml", FileMode.Open)

Dim fOut As New FileStream("emp_crypt.txt", FileMode.Create)

Dim dataIn As New StreamReader(fIn)

Dim dataOut As New StreamWriter(fOut)

Dim myData As String

myData = dataIn.ReadToEnd

dataIn.Close()

Dim toCrypt() As Byte = System.Text.Encoding.Unicode.GetBytes(myData)

Dim CryptData() As Byte = rsa.Encrypt(toCrypt, True)

dataOut.Write(CryptData)

dataOut.Close()

fIn.Close()

fOut.Close()

End Sub

Thanks for your help!

Wayne P.



Relevant Pages

  • ADO und Access-DB(Abfrage)
    ... .ConnectionString = strPathToDB ... End With ... Dim RsA As ADODB.Recordset ...
    (microsoft.public.de.vb.datenbank)
  • Re: RSA Encryption - Bad Length Error
    ... > Dim CryptData() As Byte = rsa.Encrypt ... With RSA, the message cannot be longer than the key (in your case; ... > Dim dataIn As New StreamReader ... > Dim myData As String ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Serialisieren mit VB?
    ... kann man es mit einem PropertyBag ... Dim RSa As ADODB.Recordset ... With RSa ...
    (microsoft.public.de.vb)
  • Re: RSA Encryption - Bad Length Error
    ... Wayne P. ... >> I am playing around with RSA to learn about it with the end goal of ... >> Dim dataOut As New StreamWriter ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • A VB6 program to generate CONSTants for a user defined gradient
    ... EndProperty ... It may be used for amy moral purpose. ... Dim mGreen1 As Long ... Private Sub ColorDisplay_MouseDown(Button As Integer, Shift As Integer, _ ...
    (comp.lang.basic.visual.misc)