来自给定代码的Java的加密值
public static String encrypt(String data, String sessionuser) throws Exception {
sessionuser = "HVQKcI6yo425a4d6";
data = "HelloWorld!";
byte[] keyValue = sessionuser.getBytes();
Key key = new SecretKeySpec(keyValue, "AES");
System.out.println(key);
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(data.getBytes());
String encryptedValue = Base64.encodeBase64URLSafeString(encVal);
return encryptedValue;
}
返回的encryptedValue = 48yKDDmHCgotgbTpy3FRag
SELECT (DBMS_CRYPTO.ENCRYPT
(
src => UTL_RAW.CAST_TO_RAW ('HelloWorld!'),
typ => 4096 + 256 +4,--4356, --encryption_type / AES_CBC_PKCS5 = ENCRYPT_AES + CHAIN_CBC + PAD_PKCS5
key => UTL_RAW.cast_to_raw('HVQKcI6yo425a4d6')--, encryption_key
))
from dual;
输出:E3CC8A0C39870A0A2D81B4E9CB71516A
将其从十六进制转换为基数64后: 48yKDDmHCgotgbTpy3FRag ==
请告诉我们如何获取java和oracle之间的匹配值。
由于
答案 0 :(得分:0)
您可以使用jdk的base 64编码器。它将保留' ='最后填充。
String encryptedValue = Base64.getEncoder().encodeToString(encVal);
只是在有或没有填充的情况下编码的区别。结果是相同的,最后是零到两个等号。