B
Bond
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,
~NICK~
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,
~NICK~