oracle 加密
create or replace function des3_enc(input varchar2) return varchar2
is i_data varchar2(128);
v_in varchar2(255);
i_key varchar2(128);
raw_input RAW(128) ;
key_input RAW(128) ;
decrypted_raw RAW(2048);
i_data:= input;
raw_input := UTL_RAW.CAST_TO_RAW(rpad(i_data,(trunc(length(i_data)/8)+1)*8,chr(0)));
key_input := UTL_RAW.CAST_TO_RAW('abcdef0123456789');
dbms_obfuscation_toolkit.DES3Encrypt(input => raw_input,key => key_input,encrypted_data => decrypted_raw);
return to_char(rawtohex(decrypted_raw));
end des3_enc;
oracle 解密
create or replace function des3_dec
(
input varchar2
)
return varchar2
is
i_data varchar2(2048);
i_key varchar2(2048);
v_in varchar2(2048);
i_data := input;
dbms_obfuscation_toolkit.DES3DECRYPT(input_string => UTL_RAW.CAST_TO_varchar2(i_data),key_string => 'abcdef0123456789',decrypted_string=> v_in);
v_in := rtrim(v_in,chr(0));
return v_in;
end des3_dec;
java 加密 解密
package com.example.Des3Helper;
import cn.hutool.core.util.HexUtil;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import static java.nio.charset.StandardCharsets.UTF_8;
public class Des3Helper {
public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, DecoderException, UnsupportedEncodingException {
String key = "abcdef0123456789";
String vi = "0123456789abcdef";
String input = "420105201508050014";
Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
IvParameterSpec iv = new IvParameterSpec(HexUtil.decodeHex(vi.toCharArray()));
byte[] keyBytes = new byte[24];
System.arraycopy(key.getBytes(UTF_8), 0, keyBytes, 0, 16);
System.arraycopy(key.getBytes(UTF_8), 0, keyBytes, 16, 8);
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DESede");
byte[] inBytes = new byte[((input.length() / 8) + 1) * 8];
System.arraycopy(input.getBytes(UTF_8), 0, inBytes, 0, input.length());
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv);
String encryptString = HexUtil.encodeHexStr(cipher.doFinal(inBytes), false);
System.out.println("encryptString = " + encryptString);
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv);
String decryptString = new String(cipher.doFinal(Hex.decodeHex(encryptString))).trim();
System.out.println("decryptString = " + decryptString);
}
}
标签:code,Java,RAW,varchar2,key,import,oracle,input,data
From: https://www.cnblogs.com/guanchaoguo/p/17835955.html