2 Photo and Video Encryption

This page describes the photo and video encryption method for using the SenseID API.

2.1 Customize the encryption key and IV

SenseID requires that personal data (photos and videos) must be encrypted before being uploaded via APIs. AES-256-GCM is adopted as the encryption algorithm. The key and IV required for encryption are set as follows by default.

PARAM_DECRYPT_KEY = dcbbad6765e14139a07d34b92292a672
PARAM_DECRYPT_IV = df25d188a061

To customize the key and the IV, update the environment variables PARAM_DECRYPT_KEY and PARAM_DECRYPT_IV. The key is 32 characters and the IV is 12 characters.

$ cd 1v1-private-cloud-v1.8/
$ vi .env

2.2 Encryption method

  1. Load the photo or video file.

  2. Encrypt the data with AES-256-GCM.

  3. Encode the above result with Base64.

import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.util.Base64;


public class AESCipher {
    private String key;
    private String iv;

    public AESCipher(String key, String iv) {
        this.key = key;
        this.iv = iv;
    }

    String encrypt(byte[] data) throws Exception{
        SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(Charset.forName("UTF-8")), "AES");
        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec, new GCMParameterSpec(128, iv.getBytes(Charset.forName("UTF-8"))));
        byte[] result = cipher.doFinal(data);
        return Base64.getEncoder().encodeToString(result);
    }

    byte[] decrypt(String data) throws Exception {
        SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(Charset.forName("UTF-8")), "AES");
        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec, new GCMParameterSpec(128, iv.getBytes(Charset.forName("UTF-8"))));
        byte[] result = cipher.doFinal(Base64.getDecoder().decode(data));
        return result;
    }

    public static void main(String[] args) throws Exception{
        String key = "dcbbad6765e14139a07d34b92292a672"; //key 32 bits
        String iv = "df25d188a061"; // iv 12 bits
        String data = "hello world";

        AESCipher cipher = new AESCipher(key, iv);
        String encryptedData = cipher.encrypt(data.getBytes());
        System.out.println("encrypted data: " + encryptedData);

        String decryptedData = new String(cipher.decrypt(encryptedData));
        System.out.println("decrypted data: " + decryptedData);
    }
}

Last updated