Corrupt Data error in Decryption in PostgreSQL using GnuPG

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • periwalridhi
    New Member
    • Oct 2012
    • 5

    #1

    Corrupt Data error in Decryption in PostgreSQL using GnuPG

    I am using GnuPG software for assymetric encryption in PostgreSQL.
    I have done encryption using

    Code:
    ->INSERT INTO "test1"("test") 
     ->   VALUES (pgp_pub_encrypt('testing', dearmor('------>BEGIN PGP PUBLIC KEY BLOCK-----
    ->Version: GnuPG v2.0.17 (MingW32)
    
    ->..............
    ->-----END PGP PUBLIC KEY BLOCK-----'
    
    ->)));
    and got succeded

    but when i am doing decryption with syntax:-

    Code:
    ->SELECT pgp_pub_decrypt(bytea ("test"),
    ->dearmor('-----BEGIN PGP PRIVATE KEY BLOCK-----
    ->Version: GnuPG v2.0.17 (MingW32)
    ->.............................
    ->-----END PGP PRIVATE KEY BLOCK-----'),'decrypt123')  --> ->this is the passphrase 
     -> FROM "test1";

    I am getting error as:-

    ->ERROR: Corrupt data

    ->********** Error **********

    ->ERROR: Corrupt data
    ->SQL state: 39000



    Please guide me where i am going wrong..as i need this urgently
    Last edited by Rabbit; Oct 9 '12, 03:38 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    This is from the PostgreSQL manual: Decrypting bytea data with pgp_pub_decrypt is disallowed. This is to avoid outputting invalid character data.

    Comment

    • periwalridhi
      New Member
      • Oct 2012
      • 5

      #3
      I have even tried with pgp_pub_decrypt _bytea but am getting same erorr..please help..

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        It could be that the public key and secret key you're using is out of sync. Try generating new pairs and using those. Or it could be that the password you're using for the secret key is wrong. It's hard to say because the error is so generic.

        Comment

        • periwalridhi
          New Member
          • Oct 2012
          • 5

          #5
          I regenerated the keys and even used the correct passphrase. I am still getting this error. Am i using the correct approach for public key encryption? Do i need to write some extra code for making decryption successful?
          please help.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Sorry, I haven't used that function much. Hopefully there's someone here with more experience with that.

            Comment

            • periwalridhi
              New Member
              • Oct 2012
              • 5

              #7
              Its ok and thanx for your help. I got success after making keys passwrdless. After removing passphrase column,decrypti on is successful.

              Comment

              Working...