Error using Crypt::OpenSSL::RSA - Fails loading public key - Help needed

Discussion in 'Perl' started by John Bergstrom, Aug 3, 2003.

  1. Hello everyone!

    I wrote a simple perl program to encrypt a string using
    Crypt::OpenSSL::RSA.

    Everything as described in the module documentation. The public key
    is a valid X.509 encrypted certificate.

    When I tried executing the code I get the following error:
    -------------------
    Failed to read key at blib/lib/Crypt/OpenSSL/RSA.pm (autosplit into
    blib/lib/auto/Crypt/OpenSSL/RSA/load_public_key.al) line 225
    -------------------

    Below is the exact code I that I'm trying to get working.

    Anyone any ideas?

    Thanks a lot in advance for your help!

    =TEST CODE START=======================
    use lib qw(/usr/local/lib/perl5/site_perl/5.6.1/i386-freebsd/);
    use lib qw(/usr/local/lib/perl5/site_perl/5.6.1/i386-freebsd/auto/);

    use Crypt::OpenSSL::Random;
    use Crypt::OpenSSL::RSA;

    $key_string ="-----BEGIN CERTIFICATE-----
    MIIB8zCCAVygAwIBAgIQC/mb6aRvL5BCaxMVpEBAazANBgkqhkiG9w0BAQQFADAT
    MREwDwYDVQQDEwhUZXN0Q2VydDAeFw0wMzA3MTExMjI1NDFaFw0zOTEyMzEyMzU5
    NTlaMBMxETAPBgNVBAMTCFRlc3RDZXJ0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
    iQKBgQDgp5o5a4yQbIv8RHVfJcWmacQmZmzd/GBxhoNOx7H922J48ocGqvgF8beu
    PN7wsI/fUqjm5pzFgb12+AyDN5gq0vLMA8wmKS/Cdc+3OCK5EkBE9Xi/RSoeno+Q
    o0a0M8lLl8mZBOapyq67FvLsHdQQLcZHqR8kP6Dn54FsTvyfgQIDAQABo0gwRjBE
    BgNVHQEEPTA7gBBfYCG1dYRmxJcj+J/jH9YloRUwEzERMA8GA1UEAxMIVGVzdENl
    cnSCEAv5m+mkby+QQmsTFaRAQGswDQYJKoZIhvcNAQEEBQADgYEAu9H1SWLTVi4K
    mGnsDw/ZeLtd/s8nq+k1b7Ds3LEZMBLaEyMiCkZ8zzEeGmvlJwB54XS+zhwj0RDW
    Kc2McRfsUuPkpnGMfANu3zATydGry03FCrO+uid4X91Lf+h9YL+BSewyrsnNjCx0
    0qMa+jkZ9C7vcInRRNzabtnypylza7A=
    -----END CERTIFICATE-----";

    $plaintext = "Test String";

    # not necessary if we have /dev/random:
    # Crypt::OpenSSL::Random::random_seed($good_entropy);

    Crypt::OpenSSL::RSA->import_random_seed();
    $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($key_string);

    $ciphertext = $rsa->encrypt($plaintext);

    print "ENCRYPTED: [$ciphertext]\n";
    =TEST CODE END==============
    John Bergstrom, Aug 3, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AdrianK
    Replies:
    0
    Views:
    1,534
    AdrianK
    Jul 9, 2003
  2. Cosmia Luna
    Replies:
    4
    Views:
    328
    Cosmia Luna
    Mar 11, 2012
  3. John Bergstrom
    Replies:
    0
    Views:
    99
    John Bergstrom
    Aug 3, 2003
  4. Taylor Venable
    Replies:
    0
    Views:
    198
    Taylor Venable
    Oct 4, 2007
  5. Jerry Krinock
    Replies:
    1
    Views:
    366
    Jerry Krinock
    Aug 20, 2008
Loading...

Share This Page