我有以下需要转换为Java的Oracle语句。
select utl_encode.base64_decode('2B563967613057553550327651324B6A50756C38766F3149424E69644B6D69394A5872736C773D3D') from dual;
输出应为:
F95F606B4594E4FDAF4362A33EE97CBE8D4804D89D2A68BD257AEC97.
我尝试使用Base64.decodeBase64,但输出与上面的不一样。
还尝试了以下链接
Replicate Base64 decoding of Java in PL/SQL 但不是很有帮助。
Java输出:
d81e7adfdebbeb5df4e7be79df9e74df6efae75df6e01e80e74ef9e82dfcefae85df5e3de36e04ebdeb8e01e83ebddfde00e7cef6ef7e82efbdc3dc3
任何人都可以提供帮助。
答案 0 :(得分:0)
您提供的输入是Base64字符串的十六进制表示,而不是实际的Base64字符串。以下代码将给出您要查找的结果:
String data = "2B563967613057553550327651324B6A50756C38766F3149424E69644B6D69394A5872736C773D3D";
// Quick-n-dirty method to convert hex string back to bytes
// Doesn't work if hex string has leading zeros, but for this case that doesn't apply
BigInteger bi = new BigInteger(data,16);
byte[] bdata = bi.toByteArray();
// Let's look at the real Base64 string...
String temp = new String(bdata);
System.out.println("The base64 string is: " + temp);
// Now decode the base64 string back to bytes
byte[] result = Base64.getDecoder().decode(bdata);
// Finally print the hex representation of the decoded value
System.out.print("The decoded value (in hex) is: ");
for (byte b : result)
System.out.printf("%02x", 0x000000ff & (int)b);
System.out.println();
输出:
The base64 string is: +V9ga0WU5P2vQ2KjPul8vo1IBNidKmi9JXrslw==
The decoded value (in hex) is: f95f606b4594e4fdaf4362a33ee97cbe8d4804d89d2a68bd257aec97