ユーザーがアップロードした個人データは暗号化する必要があります。暗号化アルゴリズムは AES-256-CBC を使用します。暗号化に必要なキーおよび IV は、デフォルトの設定では以下のとおりです。
key = dcbbad6765e14139a07d34b92292a672
iv = df25d188a061
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);
}
}