001package com.avaje.ebean.config.dbplatform;
002
003/**
004 * MySql aes_encrypt aes_decrypt based encryption support.
005 * 
006 * @author rbygrave
007 */
008public class MySqlDbEncrypt extends AbstractDbEncrypt {
009
010  public MySqlDbEncrypt() {
011    this.varcharEncryptFunction = new MyVarcharFunction();
012    this.dateEncryptFunction = new MyDateFunction();
013  }
014
015  private static class MyVarcharFunction implements DbEncryptFunction {
016
017    public String getDecryptSql(String columnWithTableAlias) {
018      return "CONVERT(AES_DECRYPT(" + columnWithTableAlias + ",?) USING UTF8)";
019    }
020
021    public String getEncryptBindSql() {
022      return "AES_ENCRYPT(?,?)";
023    }
024  }
025
026  private static class MyDateFunction implements DbEncryptFunction {
027
028    public String getDecryptSql(String columnWithTableAlias) {
029      return "STR_TO_DATE(AES_DECRYPT(" + columnWithTableAlias + ",?),'%Y%d%m')";
030    }
031
032    public String getEncryptBindSql() {
033      return "AES_ENCRYPT(DATE_FORMAT(?,'%Y%d%m'),?)";
034    }
035  }
036}