> ## Documentation Index
> Fetch the complete documentation index at: https://flutterwaveinc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Encryption

> Learn how to secure your payment data.

When you directly call the direct card charge [endpoints](/payment-api/card), you'll need to encrypt your payload containing the card details before making the request.

<Note>
  You do not need to worry about encryption if you use one of our backend [sdks](/sdk-plugins/backend-libraries/nodejs). You can simply pass your encryption key to the library, and it will automatically encrypt the payload before sending the request.
</Note>

To encrypt your payload manually, you will need an encryption key from the **Settings > API** section of your [dashboard](http://dashboard.flutterwave.com/). This uses the [3DES algorithm](https://en.wikipedia.org/wiki/Triple_DES) to encrypt the payload.

Below is an example of an encryption function in different languages.  In each case, the function takes the payload as a hash, converts it to JSON, encrypts and encodes it in base64:

<CodeGroup>
  ```javascript Node.js theme={null}
  function encrypt(encryptionKey, payload) {
      const text = JSON.stringify(payload);
      const forge = require("node-forge");
      const cipher = forge.cipher.createCipher(
          "3DES-ECB",
          forge.util.createBuffer(encryptionKey)
      );
      cipher.start({iv: ""});
      cipher.update(forge.util.createBuffer(text, "utf-8"));
      cipher.finish();
      const encrypted = cipher.output;
      return forge.util.encode64(encrypted.getBytes());
  }
  ```

  ```php PHP theme={null}
  function encrypt(string $encryptionKey, array $payload)
  {
      $encrypted = openssl_encrypt(json_encode($payload), 'DES-EDE3', $encryptionKey, OPENSSL_RAW_DATA);
      return base64_encode($encrypted);
   }
  ```

  ```ruby Ruby theme={null}
  def encrypt(encryption_key, payload)
        cipher = OpenSSL::Cipher.new "des-ede3"
        cipher.encrypt # Call this before setting key
        cipher.key = encryption_key
        text = payload.to_json
        cipher_text = cipher.update text
        cipher_text << cipher.final
        Base64.encode64 cipher_text
  end
  ```

  ```python Python theme={null}
  import json, requests
  import base64
  from Crypto.Cipher import DES3
  import hashlib

  def encryptData(self, key, plainText):
    blockSize = 8
    padDiff = blockSize - (len(plainText) % blockSize)
    cipher = DES3.new(key, DES3.MODE_ECB)
    plainText = "{}{}".format(plainText, "".join(chr(padDiff) * padDiff))
    encrypted = base64.b64encode(cipher.encrypt(plainText))
    return encrypted
  ```

  ```java Java theme={null}
  class PayloadEncryptor {

      private static final String ALGORITHM = "DESede";
      private static final String TRANSFORMATION = "DESede/ECB/PKCS5Padding";

      public PayloadEncryptor() {}

      public String TripleDESEncrypt(String data, String encryptionKey) {
          final String defaultString = "";
          if (data == null || encryptionKey == null) return defaultString;
          try {
              final byte[] encryptionKeyBytes = encryptionKey.getBytes();
              final SecretKeySpec secretKey = new SecretKeySpec(encryptionKeyBytes, ALGORITHM);
              final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
              cipher.init(Cipher.ENCRYPT_MODE, secretKey);

              final byte[] dataBytes = data.getBytes();
              byte[] encryptedValue = cipher.doFinal(dataBytes);
              return Base64.encodeToString(encryptedValue, Base64.DEFAULT);
          } catch (Exception exception) {
              return exception;
          }
      }
  }
  ```
</CodeGroup>
