473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trouble decoding text using RSA and bouncy castle libraries

The code segment below is in VB.net and referencing C# Bouncy Castle libraries. I get the same results when the VB code is in C#. Exact same Console output of EncryptKey and exact same "incorrect block type" exception with DecryptKey, so I don't think the language here should matter too much. The test.KEY file is a private key file we're using.

Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.     Dim input As String
  3.     Dim output As String
  4.  
  5.     input = "Feb Twenty-Fourth Two Thousand Ten"
  6.     output = EncryptKey(input)
  7.     Console.WriteLine(DecryptKey(output) <---Error!
  8.  
  9. End Sub
  10.  
  11. Private Function EncryptKey(ByVal sPlain As String) As String
  12.     Dim enc As New System.Text.UTF8Encoding
  13.     Dim result As Byte()
  14.     result = BouncyCastleCrypto(True, enc.GetBytes(sPlain))
  15.     Return Convert.ToBase64String(result)
  16. End Function
  17.  
  18. Private Function BouncyCastleCrypto(ByVal bForEncryption As Boolean, ByVal input As Byte()) As Byte()
  19.     Dim bValue64 As Byte() = {0}
  20.     Try
  21.         Dim keypair As Greenway.PrimeResearch.Encryption.Crypto.AsymmetricCipherKeyPair
  22.         Dim sr As New StreamReader("C:\Documents and Settings\xxxx\Desktop\test.KEY")
  23.         keypair = New Greenway.PrimeResearch.Encryption.OpenSsl.PemReader(sr).ReadObject
  24.         Dim cryptEngine As New Greenway.PrimeResearch.Encryption.Crypto.Encodings.Pkcs1Encoding(New Greenway.PrimeResearch.Encryption.Crypto.Engines.RsaEngine())
  25.         cryptEngine.Init(bForEncryption, keypair.Private)
  26.         bValue64 = cryptEngine.ProcessBlock(input, 0, input.Length)
  27.     Catch ex As Exception
  28.         Throw ex
  29.     End Try
  30.  
  31.     Return bValue64
  32. End Function
  33.  
  34. Private Function DecryptKey(ByVal sCipher As String) As String
  35.     Dim enc As New System.Text.ASCIIEncoding
  36.     Dim result As Byte()
  37.     result = BouncyCastleCrypto(False, Convert.FromBase64String(sCipher))
  38.     Return enc.GetString(result)
  39. End Function
  40.  
Feb 24 '10 #1
1 3707
tlhintoq
3,525 Expert 2GB
Line 7 is going to need another right parenthesis.

Aren't BouncyCastles those inflatables you rent for a 10 year old's birthday party?

Did you try contacting whomever created "BouncyCastle"? I would expect they would be more help for their product than someone NOT familiar with the product.

Try breaking down your consolidated statements so you can see each value before use:

Expand|Select|Wrap|Line Numbers
  1. result = BouncyCastleCrypto(False, Convert.FromBase64String(sCipher))
First to the Convert portion and set it to a variable, then use that variable. This way you can see what is being sent as a parameter, when you walk through the code.

Expand|Select|Wrap|Line Numbers
  1. string Converted = Convert.FromBase64String(sCipher);
  2. result = BouncyCastleCrypto(False, Converted)
Put a breakpoint at line 35 and follow it through line-by-line, watching the Locals and Autos pallets. Maybe something will come up from there.
Feb 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: TF | last post by:
I am developing a Windows Application in VB.NET that is using two class libraries CL_A (contains class A) & CL_B (contains class B). Also CL_A is used in CL_B. Now in my application when i try...
3
by: amitsoni.1984 | last post by:
Hi, I wanted to solve some linear programming problems and I was trying to use IMSL C libraries. But I couldn't get how to use it. I don't know where to write the codes and how to execute them....
1
by: Bishman | last post by:
Hi, I have been trying to get text to scroll smoothly accross a windows form using GDI+ and a timer. Changing the position of the text by a configurable amount and calling invalidate to force a...
1
by: primi | last post by:
Hello, i have studied both c and c++ at university (although by no means have they been extensive, one semester each) and i feel i have a fairly good understanding of the basics of these languages. ...
3
by: nskclr | last post by:
Hi I add a text using document.selection.createRange(). I want to add a text to the bottom of another text - similar to what we do in HTML. <p> xyz </p> <p><div...
1
by: anilraja | last post by:
how to search within text using vbscript?
3
by: f6600840 | last post by:
Hi, What function I should use if I want to clean text using perl. Example. Input for my perl based shell command is SMI-1234 566.5.2.3.4.5.5.192.168.1.1 = "huuhaa" : SMI-1234...
0
by: Basha J P M | last post by:
I am beginner in python. I am working through the tutorial examples from http://www.swig.org/ and have run into some problems. I took the following command instructions from the tutorial on...
4
by: research_stuff | last post by:
I have researched unhiding text using Javascript. I found examples unhiding text boxes. I need to unhide text when a radio button has been selected. Can someone point me to an example? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.