Storing public key and signature in a database

16 views
Skip to first unread message

alido...@gmail.com

unread,
Aug 28, 2017, 10:05:43 PM8/28/17
to Crypto++ Users
Dear All, 

I am trying to store the PK and signature to sqlite database. I first encoded the keys as: 

 pk[node].BEREncode(CryptoPP::StringSink(pkstring).Ref());


and then store them in the database. But as the PK and signature have special characteres, they are not stored correctly into the database. what I used for storing is: 

char * PK = (char*) malloc (BC.trans[l].PK.length()+1);

std::strcpy(PK,BC.trans[l].PK.c_str());

char *zSQL = sqlite3_mprintf("INSERT INTO BC (PK  VALUES ('%q');", PK);

 rc = sqlite3_exec(db, zSQL, callback, (void*)data, &zErrMsg);

free(PK); 


The string should be copied to the char, and the issue happens exactly here in copying the content into the char. I think its because the string has special characters. For hash I have the same follow but it works perfectly fine. Only for PK and signature. I used memcpy and strncpy as well. Nothing works for this and still the keys are not stored correctly in the database. 


Any thoughts? 


Regards

Ali 


Jeffrey Walton

unread,
Aug 28, 2017, 10:13:20 PM8/28/17
to Crypto++ Users


On Monday, August 28, 2017 at 10:05:43 PM UTC-4, alido...@gmail.com wrote:
Dear All, 

I am trying to store the PK and signature to sqlite database. I first encoded the keys as: 

 pk[node].BEREncode(CryptoPP::StringSink(pkstring).Ref());


and then store them in the database. But as the PK and signature have special characteres, they are not stored correctly into the database. what I used for storing is: 

char * PK = (char*) malloc (BC.trans[l].PK.length()+1);

std::strcpy(PK,BC.trans[l].PK.c_str());

char *zSQL = sqlite3_mprintf("INSERT INTO BC (PK  VALUES ('%q');", PK);

 rc = sqlite3_exec(db, zSQL, callback, (void*)data, &zErrMsg);

free(PK);


Use a BLOB, not a string type.

Or, {Hex|Base32|Base64}-encode the key. Also see


Jeff
Reply all
Reply to author
Forward
0 new messages