JSP中的解密

JSP中的解密,jsp,oracle10g,encryption,Jsp,Oracle10g,Encryption,如何(使用JavaServerPages)解密用PL/SQL加密的数据 dbms_obfuscation_toolkit.DESEncrypt 钥匙是已知的。我是JSP新手,所以请解释您的答案。此加密方法dbms\u obfusation\u工具包。DESEncrypt允许您拥有密码或仅以8个字符的倍数说出密码字符串。下面我编写了一个示例JSP页面,它向您显示一个字符串是加密和解密的 先决条件:此代码使用库org.apache.commons.codec.binary,下载org.apache

如何(使用JavaServerPages)解密用PL/SQL加密的数据

dbms_obfuscation_toolkit.DESEncrypt

钥匙是已知的。我是JSP新手,所以请解释您的答案。

此加密方法
dbms\u obfusation\u工具包。DESEncrypt
允许您拥有密码或仅以8个字符的倍数说出密码字符串。下面我编写了一个示例JSP页面,它向您显示一个字符串是加密和解密的

先决条件:此代码使用库org.apache.commons.codec.binary,下载org.apache.commons.codec.binary 1.5二进制文件并将其放在lib文件夹中

<%@ page import="java.io.*" %>
<%@ page import="java.security.*" %>
<%@ page import="javax.crypto.*" %>
<%@ page import="javax.crypto.spec.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="org.apache.commons.codec.binary.*" %>

    <HTML>
    <HEAD>
    <TITLE> Cheers! </TITLE>
    </HEAD>
    <BODY>

    <%
        String algorithm1 = "DES";//magical mystery constant
        String algorithm2 = "DES/CBC/NoPadding";//magical mystery constant
        IvParameterSpec iv = new IvParameterSpec( new byte [] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } );//magical mystery constant
        Cipher cipher;
        SecretKey key;
        String k="12345abc"; //Just a random pick for testing
        key = new SecretKeySpec( k.getBytes("UTF-8"), algorithm1 );
        cipher = Cipher.getInstance( algorithm2 );

        String str="test4abc"; //Test String, 8 characters

        cipher.init( Cipher.ENCRYPT_MODE, key, iv ); //normally you could leave out the IvParameterSpec argument, but not with Oracle

        byte[] bytes=str.getBytes("UTF-8");

        byte[] encrypted = cipher.doFinal( bytes );

        String encoded = new String( Hex.encodeHex( encrypted ) );
        out.println( "Encrypted/Encoded: \"" + encoded + "\"" );



        cipher.init( Cipher.DECRYPT_MODE, key, iv );    

        //byte [] decoded = org.apache.commons.codec.binary.Hex.decodeHex( encoded.toCharArray( ) );
        byte [] decoded = Hex.decodeHex( encoded.toCharArray( ) );

        String decrypted = new String (cipher.doFinal( decoded ));
        out.println("DECRYPTED: \"" + decrypted + "\"" );
    }

    %>  
    </BODY>
    </HTML>

干杯
这可能会解决您的问题。 干杯

可能的副本,另请参见: