Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/pgcrypto.sgml`
550314f59f964df9ead6de7256799e8f6ff29a0cc0e8d1870000000100000fa0
  </indexterm>

<synopsis>
pgp_sym_encrypt(data text, psw text [, options text ]) returns bytea
pgp_sym_encrypt_bytea(data bytea, psw text [, options text ]) returns bytea
</synopsis>
   <para>
    Encrypt <parameter>data</parameter> with a symmetric PGP key <parameter>psw</parameter>.
    The <parameter>options</parameter> parameter can contain option settings,
    as described below.
   </para>
  </sect3>

  <sect3 id="pgcrypto-pgp-enc-funcs-pgp-sym-decrypt">
   <title><function>pgp_sym_decrypt()</function></title>

   <indexterm>
    <primary>pgp_sym_decrypt</primary>
   </indexterm>

   <indexterm>
    <primary>pgp_sym_decrypt_bytea</primary>
   </indexterm>

<synopsis>
pgp_sym_decrypt(msg bytea, psw text [, options text ]) returns text
pgp_sym_decrypt_bytea(msg bytea, psw text [, options text ]) returns bytea
</synopsis>
   <para>
    Decrypt a symmetric-key-encrypted PGP message.
   </para>
   <para>
    Decrypting <type>bytea</type> data with <function>pgp_sym_decrypt</function> is disallowed.
    This is to avoid outputting invalid character data.  Decrypting
    originally textual data with <function>pgp_sym_decrypt_bytea</function> is fine.
   </para>
   <para>
    The <parameter>options</parameter> parameter can contain option settings,
    as described below.
   </para>
  </sect3>

  <sect3 id="pgcrypto-pgp-enc-funcs-pgp-pub-encrypt">
   <title><function>pgp_pub_encrypt()</function></title>

   <indexterm>
    <primary>pgp_pub_encrypt</primary>
   </indexterm>

   <indexterm>
    <primary>pgp_pub_encrypt_bytea</primary>
   </indexterm>

<synopsis>
pgp_pub_encrypt(data text, key bytea [, options text ]) returns bytea
pgp_pub_encrypt_bytea(data bytea, key bytea [, options text ]) returns bytea
</synopsis>
   <para>
    Encrypt <parameter>data</parameter> with a public PGP key <parameter>key</parameter>.
    Giving this function a secret key will produce an error.
   </para>
   <para>
    The <parameter>options</parameter> parameter can contain option settings,
    as described below.
   </para>
  </sect3>

  <sect3 id="pgcrypto-pgp-enc-funcs-pgp-pub-decrypt">
   <title><function>pgp_pub_decrypt()</function></title>

   <indexterm>
    <primary>pgp_pub_decrypt</primary>
   </indexterm>

   <indexterm>
    <primary>pgp_pub_decrypt_bytea</primary>
   </indexterm>

<synopsis>
pgp_pub_decrypt(msg bytea, key bytea [, psw text [, options text ]]) returns text
pgp_pub_decrypt_bytea(msg bytea, key bytea [, psw text [, options text ]]) returns bytea
</synopsis>
   <para>
    Decrypt a public-key-encrypted message.  <parameter>key</parameter> must be the
    secret key corresponding to the public key that was used to encrypt.
    If the secret key is password-protected, you must give the password in
    <parameter>psw</parameter>.  If there is no password, but you want to specify
    options, you need to give an empty password.
   </para>
   <para>
    Decrypting <type>bytea</type> data with <function>pgp_pub_decrypt</function> is disallowed.
    This is to avoid outputting invalid character data.  Decrypting
    originally textual data with <function>pgp_pub_decrypt_bytea</function> is fine.
   </para>
   <para>
    The <parameter>options</parameter> parameter can contain option settings,
    as described below.
   </para>
  </sect3>

  <sect3 id="pgcrypto-pgp-enc-funcs-pgp-key-id">
   <title><function>pgp_key_id()</function></title>

   <indexterm>
    <primary>pgp_key_id</primary>
   </indexterm>

<synopsis>
pgp_key_id(bytea) returns text
</synopsis>
   <para>
    <function>pgp_key_id</function> extracts the key ID of a PGP public or secret key.
    Or it gives the key ID that was used for encrypting the data, if given
    an encrypted message.
   </para>
   <para>
    It can return 2 special key IDs:
   </para>
   <itemizedlist>
    <listitem>
     <para>
      <literal>SYMKEY</literal>
     </para>
     <para>
      The message is encrypted with a symmetric key.
     </para>
    </listitem>
    <listitem>
     <para>
     

Title: PGP Encryption and Decryption Functions
Summary
The document describes various PGP encryption and decryption functions, including symmetric-key encryption with pgp_sym_encrypt() and decryption with pgp_sym_decrypt(), public-key encryption with pgp_pub_encrypt() and decryption with pgp_pub_decrypt(), as well as a function to extract the key ID from a PGP public or secret key, pgp_key_id(), and explains the usage and options for each function, including handling of bytea data and password-protected secret keys.