Ebean手动解密 [英] Ebean manual decryption
问题描述
我已经使用此 SO帖子。但是我想知道如何从SQL客户端手动解密该字段以进行调试。我想要这个信息用于Mysql(Prod数据库),最好是H2(dev数据库)。根据E-bean文档,Mysql使用AES_ENCRYPT / AES_DECRYPT,H2使用ENCRYPT / DECRYPT函数。
I have successfully setup encryption for a field in my model using the answer provided in this SO post. But I would like to know how to manually decrypt the field from SQL client for debugging purposes. I want this information for Mysql (Prod database) and preferably for H2 (dev database). As per E-bean documentation Mysql uses AES_ENCRYPT/AES_DECRYPT and H2 uses ENCRYPT/DECRYPT functions.
@Encrypted
@Column(columnDefinition="varchar(50)")
public String password;
注意:我已将加密字段的数据类型设置为varchar而不是二进制,如下所示。因此,Ebean可能会将Hex生成二进制数据。
Note: I have set the datatype of encrypted field as varchar instead of binary as shown below. Hence Ebean might additionally Hex the generated binary data.
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";
}
}
推荐答案
设法确定答案。对于My-SQL
I managed to Identify the answer. For My-SQL
解密:
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: / p>
encrypt:
ENCRYPT('AES', STRINGTOUTF8('<encryption-key>'), STRINGTOUTF8('<text to be encrypted>'))
解密:
TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8('<encryption-key>'), '<text to be encrypted>')))
这篇关于Ebean手动解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!