Hi! I'm using MS Access for a database to store a public key.
My java application should store the bytes in the database and then
load the bytes later in the application where the bytes are converted
back to the public key.
Here's my sql statement to insert the Public Key:
String sql = "INSERT INTO Users (username, password, publicKey, status)
VALUES ('"
+ username + "', '" + password + "', '"
+ publicKey.getEncoded() + "', " + 0 + ")";
The attribute publicKey is OLE Object.
Later in my application, I will load the public key again using
result.getByes("publicKey");
Then I do some translation to convert the bytes back to PublicKey (this
I have figured out no problem).
PROBLEM: My problem is that the bytes after loading the public key are
different from when i saved them.
For example:
when i first store the public key, I execute the following code:
public static void createAccount(String username, String password,
PublicKey publicKey) throws SQLException
{
System.out.println("Storing public key: " +
publicKey.getEncoded());
String sql = "INSERT INTO Users (username, password, publicKey,
status) VALUES ('"
+ username + "', '" + password + "', '"
+ publicKey.getEncoded() + "', " + 0 + ")";
ConnectionPool.executeUpdate(sql);
}
------> This prints: "Storing public key: [B@a18aa2
Later on, I load the public key (bytes):
public static AddressBook loadAddressBook(String username) throws
SQLException
{
String sql = "SELECT * from Contacts WHERE userOwner='" +
username + "'";
ResultSet results = ConnectionPool.executeQuery(sql);
AddressBook addressbook = new AddressBook();
while(results.next())
{
String contactUsername = results.getString("username");
byte[] temp = results.getBytes("publicKey");
System.out.println("Loading public key: " + temp);
PublicKey publicKey = Conversions.toPublicKey(temp);
int status = results.getInt("status");
Contact contact = new Contact(contactUsername, publicKey,
status);
addressbook.addContact(contact);
}
return addressbook;
}
-----> This prints: "Loading public key: [B@1a7bf11
I'm very confused about this and it's been bothering me for a long
time. I just want to store a PublicKey into MS Access and then load it
again later on. If anyone has any suggestions, please let me know.
Thanks in advance!
jan V - 13 Sep 2005 13:10 GMT
Didn't you already post this not many hours ago?
Roedy Green - 13 Sep 2005 20:42 GMT
>INSERT INTO Users (username, password, publicKey,
what datatype is publicKey? It has better be some sort of blob/byte
type not character. If character you will get some translation.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
zhaoyh.hxtt@gmail.com - 24 Sep 2005 16:56 GMT
> Hi! I'm using MS Access for a database to store a public key.
>
[quoted text clipped - 69 lines]
>
> Thanks in advance!
EricF - 25 Sep 2005 05:25 GMT
>> Hi! I'm using MS Access for a database to store a public key.
>>
[quoted text clipped - 69 lines]
>>
>> Thanks in advance!
What the $$$ is an ole object? Is an encrypted key an ole object? Probably
not. What you probably want to do is store it as a text type - though see what
Access has to say about text types.
Bjorn Abelli - 25 Sep 2005 15:05 GMT
"Bond" wrote...
> Hi! I'm using MS Access for a database to store a public key.
[snip]
> PROBLEM: My problem is that the bytes after loading the
> public key are different from when i saved them.
You haven't shown that they *are* different...
[snip]
> System.out.println("Storing public key: " +
> publicKey.getEncoded());
[snip]
> ------> This prints: "Storing public key: [B@a18aa2
[snip]
> System.out.println("Loading public key: " + temp);
[snip]
> -----> This prints: "Loading public key: [B@1a7bf11
Quite logical.
When you use the "println" method in this way, it doesn't print out the
*content* of the byte array. It only prints what comes out of the array's
toString-method.
In this case it prints out
- The type of array: [B (array of bytes)
- The at-sign: @
- The hexadecimal hashcode of the array-object
The two arrays are logically two different *objects*, with separate
identifiers, even though their contents very well might be the same. Hence
it would be no surprise to get two different hashcodes.
> I'm very confused about this and it's been bothering me for
> a long time. I just want to store a PublicKey into MS Access
> and then load it again later on.
So, have you really checked that what you store isn't what you get?
// Bjorn A