为什么加密和base64编码的文本在Windows和Linux上显示不同 [英] Why encrypted and base64 encoded text appears different on Windows and Linux
问题描述
任何帮助/建议将不胜感激
这里是hibernate拦截器的一个代码片段
public boolean onLoad(Object entity,Serializable arg1 ,Object [] state,String [] propertyNames,Type [] arg4)throws CallbackException {
if(key!= null){
try {
if(entity instanceof BasicData){$ b (int i = 0; i< state.length; i ++){
if(state [i] instanceof String){
String cipherText =(String)state [i ]。
byte [] cipherTextBytes = Base64Coder.decode(cipherText);
byte [] plainTextBytes = dCipher.doFinal(cipherTextBytes);
state [i] = new String(plainTextBytes,UTF8);
}
}
返回true;
}
} catch(Exception e){
e.printStackTrace();
}} return false;}
您控制双方,编码和解码,更好的方式使用DatatypeConverter:
String buffer = DatatypeConverter.printBase64Binary(symKey);
byte [] putsSymKey = DatatypeConverter.parseBase64Binary(buffer);
I have a legacy system that uses hibernate interceptor to encrypt (and encode) and decrypt (and decode) some fields on some database tables. It makes use of the OnSave, OnLoad and OnFlushDirty methods. This code turns out to be buggy as data read from this system, when transferred to another application still has some of the records encrypted and encoded (some encrypted multiple times). The challenge for me here is that I could perform the decryption and decoding (as many times as necessary) when the receiving application is on a Windows machine. I get a BadPaddingException when I try to repeat the same thing when the receiving application is a linux VM.
Any help/suggestions will be greatly appreciated
here is a snippet of the hibernate interceptor
public boolean onLoad(Object entity, Serializable arg1, Object[] state, String[] propertyNames, Type[] arg4) throws CallbackException {
if (key != null){
try {
if (entity instanceof BasicData) {
for (int i = 0; i < state.length; i++) {
if (state[i] instanceof String){
String cipherText = (String)state[i];
byte[] cipherTextBytes = Base64Coder.decode(cipherText);
byte[] plainTextBytes = dCipher.doFinal(cipherTextBytes);
state[i] = new String(plainTextBytes, "UTF8");
}
}
return true;
}
} catch (Exception e) {
e.printStackTrace();
}}return false;}
If you control both sides, encode and decode, better way to use DatatypeConverter:
String buffer = DatatypeConverter.printBase64Binary( symKey );
byte[] supposedSymKey = DatatypeConverter.parseBase64Binary( buffer );
这篇关于为什么加密和base64编码的文本在Windows和Linux上显示不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!