I'm trying to use the openssl library to implement RSA encryption / decryption 
using a public and private key. I think I could resume what I'm trying to do 
with converting this C code to nim: 
<http://hayageek.com/rsa-encryption-decryption-openssl-c>/

I'm unable to properly load my public and private key using openssl: 
    
    
    var rsa: PRSA
    var public_key: string = """-----BEGIN PUBLIC KEY-----
      MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRQHDdjYg59eEGUzfFhe1k4J4n
      FKsFMJAyL/K1qmURJ8ecnBJNpAzAuSc19ncFLsCNjP9DL/oIQO42+3Z9Wc3d5GMB
      XheYOdu5+5/l+0RIt3Z2fC1E/jugLW9ThAJsmYG42u4bbQq1TEsgSyzcydO13UPy
      +FC6ovs+pRBY02sH6QIDAQAB
      -----END PUBLIC KEY-----"""
    
    var bio = BIO_new_mem_buf(addr publickey, -1)
    rsa = PEM_read_bio_RSA_PUBKEY(bio, rsa.addr, nil, nil)
    
    if rsa.isNil:
        echo "ERROR: Could not load PUBLIC KEY!  PEM_read_bio_RSA_PUBKEY FAILED"
        echo ERR_error_string(ERR_get_error(), nil)
    
    
    Run

This gets me the error: 
    
    
    ERROR: Could not load PUBLIC KEY!  PEM_read_bio_RSA_PUBKEY FAILED
    error:0909006C:PEM routines:get_name:no start line
    
    
    Run

I have the same error when I try loading the private key.

I have also tried loading the keys from files, but no luck there either... 
Would really appreciate if someone could give me a tip there, as I really don't 
understand what's going on, and the documentation on Nim interaction with 
openssl is extremely scarce to say the least...

PS: something is wrong with the registration on this forum... Had to make a 
second account with a temp email because I never received the confirmation 
email on my real email address (yes, I checked spams). Someone might want to 
take a look a this....

Reply via email to