B4J Question [RDC] retrieving a byte array (Salt) from the DB and "seeing" it

Cableguy

Expert
Licensed User
Longtime User
Hi guys

I created a very small sub to create test Users into my DataBase.Login table.
The columns are Username, EMail, Salt, Hash.
Using Heidi I can see the columns contents, including the byte arrays(?) from the Salt and Hash fields.

I then created a sub to retrieve the Salt for that User, using the username and EMail fields as search criteria.
The sub returns successfully one (1) record, which is what I want, but I just can't find a way to either test the retrieved bytes length, nor to convert them to a "visible" format...
Since I am "throwing" the retrieved value from one module into another, I need to make sure of the bytes integrity...

but just assigning the value is throwing me a cast exception!

B4X:
Main.ToolBar1.MyLogIn.Salt=result.Columns.Get("Salt")

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Integer cannot be cast to [Byte]

From what I can figure, apparently I am NOT getting the Byte from my table... but then, what am I getting and why?

[EDIT]

so after a few more minutes digging into this, and changing from "result.columns.get...." to "result.rows.get(0)" I am now getting something, apparently an Object...
But I don't get it, how do I get my bytes???
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I remember once i stored bytes into my DB, when i tried to retrieve them i had a lot of problems, the way i found to solve the issue was to convert the bytes to a string and then store it in the database.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
try
B4X:
 Dim salts As StringBuilder
 salts.Initialize
 For Each b As Byte In salt
 salts.Append(Bit.ToHexString(b))
 Next
 Log(salts.ToString)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I have used blobs to store and retrieve images using the built-in blobtoimage/imagetoblob subs...
I am storing the salt as VarBinary with a size of 255, and Heidi seems to internally convert it to hex for easy "viewing" of contents.

I will try @Daestrum approach to see if it's doable and post my results later tonight...
Now it's time for my day job!
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
try
B4X:
Dim salts As StringBuilder
salts.Initialize
For Each b As Byte In salt
salts.Append(Bit.ToHexString(b))
Next
Log(salts.ToString)

I get "Object cannot be converted to iterable list"
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
At the end I went with @Enrique Gonzalez R suggestion and converted my bytes to hexString before saving into the database.
So now I have a working User Login implementation in my app.

Thanks once again Enrique
 
Upvote 0
Top