By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

How to store keys generated from Crypt::RSA module??

P: 3
Hi All,

I'm using Crypt::RSA module for generating public & private keys. Now the problem is that when I'm storing the keys in the database, and again bringing them to do the signature or verification the Crypt::RSA module is unable to understand the key format. I'm storing the keys in the Varchar field of the MySQL.

Could any body tell me when storing the keys in the databases what would be the type of the field or how to work with the keys??

Thanks in advance.

Jan 3 '08 #1
Share this Question
Share on Google+
7 Replies

Expert 100+
P: 971
Have you tried to enter the key into the database with something other than your script? Can you show the relevant code from your script where the key is being inserted?

Jan 3 '08 #2

P: 3
Hi Kelvin,

My Code is as follows...

Expand|Select|Wrap|Line Numbers
  1. my ($public, $private) = 
  2.         $rsa->keygen ( 
  3.             Identity  => '',
  4.             Size      => 512,  
  5.             Password  => 'abc', 
  6.             Verbosity => 1,
  7.         ) or die $rsa->errstr();
  9. $sth = $dbh->prepare ("insert into test values('$private');"); 
  10. $sth->execute ();
Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare ("select t1 from test;"); 
  2. $sth->execute ();
  4. $pr = $sth->fetchrow;

Giving error when trying to use the string retrieved from the database
Expand|Select|Wrap|Line Numbers
  1. my $signature = 
  2.         $rsa->sign ( 
  3.             Message    => $message, 
  4.             Key        => $pr
  5.         ) || die $rsa->errstr();
Expand|Select|Wrap|Line Numbers
  1. Can't locate object method "n" v
  2. ia package "Crypt::RSA::Key::Private=HASH(0x23b7ec4)" (perhaps you forgot to load "Crypt::RSA::Key::Private=HASH(0x23b7ec4)"?) at  C:/usr/site/lib/Crypt/RSA/SS/ line 42.

Thanx in advance.

Jan 4 '08 #3

Expert 100+
P: 971
Are you using the strict and warnings pragmas?

Also, try changing this part of your query for the insert.
Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare ('INSERT INTO test VALUES(?)'); 
  2. $sth->execute ($private);
Then on the select statement remove the semi-colon in the statement.
Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare ('SELECT t1 FROM test');
Also, change the following.
Expand|Select|Wrap|Line Numbers
  1. $pr = $dbh->fetchrow_arrayref;
Are you using any error checking if the query fails?
Expand|Select|Wrap|Line Numbers
  1. my $query = $dbh->prepare('SELECT col1 FROM table') or die $DBI::errstr;
Give that a go and see if that takes care of your issues.

Jan 4 '08 #4

P: 3
Hi Kelvin,

Thanx for the reply.

My database query is running. I can store the key(s) in the database as a varchar format and retrieve in correctly. The problem is showing when I'm using that varchar formatted key to again use the Crypt::RSA algorithm.

It simply does not call the methods of the Crypt::RSA algo. The algo is unable to recognize that format.

I've even tried format BLOB, TEXT but of no use.

Jan 4 '08 #5

Expert 100+
P: 971
What database are you using?

If your "Key" includes special characters, then your 'Key" will need to be escaped before you insert it into the database. To me that sounds like the problem. If that is not the case the post a question in the relevant database forum they might be able to help you further, especially if it is a storage issue.

Jan 7 '08 #6

P: 1
Not sure if this has been resolved. The error message (Can't locate object method "n" via package "Crypt::RSA::Key::Private=HASH(0x23b7ec4)" ...) means you were calling the "n" method on the string $pr (interpreted as a package "Crypt::RSA::Key::Private=HASH(0x23b7ec4)"). The $pr need to be a Crypt::RSA::Key::Private object.
Dec 5 '10 #7

Expert Mod 2.5K+
P: 3,503
@CZJH I highly doubt that the OP is working on this issue still. Looking at their profile, they have not visited this site since they posted this questions.


Dec 5 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.