How to encrypt and decrypt the password using RSA algorithm in NAV 2016

srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
edited 2020-10-08 in NAV Three Tier
Hi All,

I need to encrypt the password which uses "Public Key" and send the same using HttpWebRequest, it will give reponce which is encrypted.

I can send and receive the data but cannot encrypt and decrypt.

Please help to encrypt and decrypt the data using RSA algorithm.

Thanks in Advance,
Srinivas.

Best Answers

Answers

  • ftorneroftornero Member Posts: 325
    Hello @srinivas_dynamics,

    If you need to encrypt/decrypt the password using a private/public key you must to use an external program like gnuPG's Gpg4win (https://gnupg.org/index.html), and call it from NAV2016.

    Regards.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    ftornero wrote: »
    Hello @srinivas_dynamics,

    If you need to encrypt/decrypt the password using a private/public key you must to use an external program like gnuPG's Gpg4win (https://gnupg.org/index.html), and call it from NAV2016.

    Regards.

    Can you please explain how to use..
  • ftorneroftornero Member Posts: 325
    Hello @srinivas_dynamics,

    Could you elaborate a little about this.

    The remote site give to you a "public key" and you give to them another "public key" or how is the real process .

    Regards.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    edited 2020-10-10
    ftornero wrote: »
    Hello @srinivas_dynamics,

    Could you elaborate a little about this.

    The remote site give to you a "public key" and you give to them another "public key" or how is the real process .

    Regards.

    HI @ftornero ,

    We don't provide any kind of keys. we will get the keys from remote site/system and we need to use the same key for encryption or decryption.

    Thanks.
  • ftorneroftornero Member Posts: 325
    Hello @srinivas_dynamics ,

    Ok, maybe you need to calculate a data hash with this key and SHA1 o similar.

    Have you any documentation that you can share in this forum?

    Regards.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    edited 2020-10-13
    ftornero wrote: »
    Hello @srinivas_dynamics ,

    Ok, maybe you need to calculate a data hash with this key and SHA1 o similar.

    Have you any documentation that you can share in this forum?

    Regards.

    Please check https://www.devglan.com/online-tools/rsa-encryption-decryption

    h63d8vpda4rq.png

    I need to encrypt or decrypt in the same way.

    Thanks.
  • ftorneroftornero Member Posts: 325
    Hello @srinivas_dynamics,

    In the previous example you can't encrypt and decrypt with the same key, you encrypt with the public key and decrypt with the private key like I said in my first message.

    So for this you need to generate a public/private key pair in your system and send the public key to the other part

    They must to do the same and send to you the public key, with this public key you encrypt the information that you send to them and with your public key they encrypt the information that they send to you.

    The private keys, that are not interchangend, are to decrypt de information in both sides.

    Could you confirm please.

    Regards.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    ftornero wrote: »
    Hello @srinivas_dynamics,

    In the previous example you can't encrypt and decrypt with the same key, you encrypt with the public key and decrypt with the private key like I said in my first message.

    So for this you need to generate a public/private key pair in your system and send the public key to the other part

    They must to do the same and send to you the public key, with this public key you encrypt the information that you send to them and with your public key they encrypt the information that they send to you.

    The private keys, that are not interchangend, are to decrypt de information in both sides.

    Could you confirm please.

    Regards.

    Hi @ftornero ,

    We have Public Key which is provided by the remote site. The same key is shown in the above screenshot.

    Thanks.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    ftornero wrote: »
    To test the above code you can use this PEM file
    -----BEGIN RSA PRIVATE KEY-----
    MIIEpAIBAAKCAQEAs1ftQXhqoh328GUxLzsSRyteshWrZqQrqgrmpW+kKMgxOSe0
    Bt6YpoUcSQCwIAqqvArsSwsqaLmTShC6XS+pTq+FAfyJa0ECwDRCYm9efwFF6O2L
    QlF518uCoc4LRPmFEOLi9dIwNfxKoCfVEgdQLmsUEkufBA474SJ8NrUZ39W8kYss
    QSndcOQlyfeF7ergYvfGML5YpX9L9uWAmjVAWPFF605AyqULBQoh7tpwFUzQqYXd
    HYimVJj4tYM5BXmOnvS/PFb/wtnfIr2sjqnQ99tSYNt1VvppBQ0vbMkJgteJp5o9
    1l4eHDpPfFDqPBvnsCGCbsNaRaHWrLYEH9l8YQIDAQABAoIBADnwCeHAuRIug/wd
    dMpBVyJOzITTo0/Bcam5Y9HGQ045fk1smigt+TqyffTHmB6B0650COolbUnvybl/
    tfUs1JFq+p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zfzVIlq3/rZWZeSBSJs9mFL37V/2FkOgbTM1DvJVpRS8
    5MPRRcUfDUUFcVif0+KCPQxpnnAA5ue2/mO7jB7dA+9eNurv3e0PJw==
    -----END RSA PRIVATE KEY-----
    

    Or you can create a new one using OpenSSL and this commands:
    openssl genrsa -des3 -out private.pem 2048
    
    openssl rsa -in private.pem -out private_unencrypted.pem -outform PEM
    


    Regards

    Hi @ftornero ,

    Thanks for your help.
    We have Successfully Encrypted the Password using the above Code.
    But we have Public Key so we have changed the key type to public.
  • ftorneroftornero Member Posts: 325
    Hello @srinivas_dynamics,

    Well in this case, with only the public key, you will not being able to decrypt.

    Regards.
  • srinivas_dynamicssrinivas_dynamics HyderabadMember Posts: 34
    ftornero wrote: »
    Hello @srinivas_dynamics,

    Well in this case, with only the public key, you will not being able to decrypt.

    Regards.

    Hi @ftornero ,

    In my case just encryption is required and decryption will be done by remote party.
    They just provided public key so I need to encrypt the data.

    Thanks.
Sign In or Register to comment.