0

I encrypt a string in c# (RijndaelManaged), which returns a byte array.

I want to save that byte array to a database in order to get it decrypted later in the android device.

I have tried converting it to base64 in c#, But as I understand android doesnt support base64 decoding before API8.

Is there another way saving the byte array in the DB, so I can later fetch it and decrypt it on android?

10X

SuperFrog
  • 7,631
  • 9
  • 51
  • 81

2 Answers2

0

Update :

you can implement the base64 encoding yourself on both sides so that you can be sure, you can see example code of how to implement Base64 encoding and decoding in languages like c, C++, java, and javascript on wikibooks

Yes, if you are using SQL Server, you can use VarBinary

you can read more about insert a byte array into database in this SO question

You can insert BLOB Data in SQLITE and MySql too

Community
  • 1
  • 1
Vamsi
  • 4,237
  • 7
  • 49
  • 74
  • I am using MySql, which be later will be converted to sqlite. – SuperFrog Nov 14 '11 at 12:12
  • Check [How do i store and retrieve a blob from sqlite](http://stackoverflow.com/questions/625029/how-do-i-store-and-retrieve-a-blob-from-sqlite) to see how to store blo data in sqllite – Vamsi Nov 14 '11 at 12:22
0

You can find Java Base64 decoders everywhere http://www.source-code.biz/base64coder/java/ , add it to your Android project and you're off.

If not, just translate each byte into two hexadecimal digits in C#, and then back in Android. It's very easy to do so yourself.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • I`m Trying the java class, but the result is different then what originally was created in the C# code. I am trying to figure out why is that. – SuperFrog Nov 14 '11 at 12:11
  • I say don't worry about it at all. Convert to hex and forget about it. – zmbq Nov 14 '11 at 12:14
  • I have tried both (Base64 and Hex), and from some reason some of the bytes I get in android are negative, while the original c# byte array is all positive. Any ideas? – SuperFrog Nov 14 '11 at 12:36
  • Yes, make sure you're using unsigned integers (and shorts) when building the byte value again. – zmbq Nov 14 '11 at 12:40
  • Ok - did the Java Base64 solution. 10X :) – SuperFrog Nov 14 '11 at 13:49