【问题标题】:Ebean manual decryptionEbean手动解密
【发布时间】:2015-05-25 10:01:50
【问题描述】:

我已经使用this SO 帖子中提供的答案成功地为我的模型中的一个字段设置了加密。但我想知道如何从 SQL 客户端手动解密该字段以进行调试。我想要 Mysql(Prod 数据库)的这些信息,最好是 H2(开发数据库)。根据 E-bean 文档,Mysql 使用 AES_ENCRYPT/AES_DECRYPT 而 H2 使用 ENCRYPT/DECRYPT 函数。

  @Encrypted
  @Column(columnDefinition="varchar(50)")
  public String password;

注意:我已将加密字段的数据类型设置为 varchar 而不是二进制,如下所示。因此,Ebean 可能会另外对生成的二进制数据进行 Hex。

class CustomEncryptKey implements EncryptKey{ 

   private String tableName;
   private String columnName;

   public CustomEncryptKey(String tableName, String columnName){
      this.tableName = tableName;
      this.columnName = columnName;
   }

 @Override 
 public String getStringValue() {     
        return "my-encryption-key";     
 }     
}

【问题讨论】:

    标签: mysql encryption playframework-2.0 ebean


    【解决方案1】:

    我设法找出答案。对于 MySQL

    解密:

    SELECT CAST(AES_DECRYPT(encrypted-field,'my-encryption-key') as CHAR(50)) from table
    

    加密:

    SELECT AES_ENCRYPT(encrypted-field,'my-encryption-key') from table;
    

    对于 H2:

    加密:

    ENCRYPT('AES', STRINGTOUTF8('<encryption-key>'), STRINGTOUTF8('<text to be encrypted>'))
    

    解密:

    TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8('<encryption-key>'), '<text to be encrypted>')))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多