zoukankan      html  css  js  c++  java
  • oracle使用javasource

    在oracle 11g中使用javasource

    首先定义javaSource

    create or replace and compile java source named "Encrypt1" as
    import java.security.SecureRandom;

    import javax.crypto.Cipher;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.DESKeySpec;


    public class Encrypt1 {
      private static final byte[] DES_KEY = { 21, 1, -110, 82, -32, -85, -128, -65 };
      public static String decryptBasedDes(String cryptData) {
        String decryptedData = null;
        try {
          // DES算法要求有一个可信任的随机数源
          SecureRandom sr = new SecureRandom();
          DESKeySpec deskey = new DESKeySpec(DES_KEY);
          // 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
          SecretKey key = keyFactory.generateSecret(deskey);
          // 解密对象
          Cipher cipher = Cipher.getInstance("DES");
          cipher.init(Cipher.DECRYPT_MODE, key, sr);
          // 把字符串解码为字节数组,并解密
          decryptedData = new String(cipher.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(cryptData)));
        } catch (Exception e) {
          throw new RuntimeException("解密错误,错误信息:", e);
      }
      return decryptedData;
     }
    }

    定义function

    CREATE OR REPLACE FUNCTION Encrypt11 (cryptData IN STRING)
       RETURN String
    IS
       LANGUAGE JAVA
       NAME 'Encrypt1.decryptBasedDes(java.lang.String) return String';

    调用:

    declare abc String(50);
    begin
      abc:=Encrypt11('aT3dGMPB2FEMba0K881Jmg==');
      dbms_output.put_line(abc);
      end;

  • 相关阅读:
    Mybatis批处理
    Mybatis兼容C3P0连接池
    一对多,多对一查询
    缓存
    动态sql
    mybatis 日志记录
    python学习day07-encode和decode
    python学习day07---三级目录优化
    python学习day06练习---三级目录
    python学习day06--02字典增删差改以及字符串的一些方法
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331329.html
Copyright © 2011-2022 走看看