2016-03-21 15 views
0

私は現在Javaでパスワードを暗号化している(Jbossサーバーで実行中)ソリューションで作業しており、Data Powerに送信してDataPowerで暗号解除します。私はJavaでパスワードを暗号化することができました。私はDataPowerに多くの知識を持っていません。私はデータパワーで解読するコードを持っていますが、データパワーに鍵を送る方法はわかりません。誰でも私を助けてくれますか?コードは以下のようになります 暗号化コード(Java) package test;Javaで暗号化、データ電源で復号化

import java.io.ByteArrayOutputStream; 
import java.security.Key; 
import java.util.ArrayList; 

import javax.crypto.Cipher; 
import javax.crypto.spec.IvParameterSpec; 
import javax.crypto.spec.SecretKeySpec; 

import sun.misc.BASE64Decoder; 
import sun.misc.BASE64Encoder; 



public class Test { 


    private static final String ALGO = "AES"; 

    public static String encrypt(String data,String secretKey) throws Exception { 
    Key key = generateKey(secretKey); 
    byte[] ivAES = {(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22,(byte)0x22}; 
    IvParameterSpec ivspec = new IvParameterSpec(ivAES); 
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
    cipher.init(Cipher.ENCRYPT_MODE, key, ivspec); 
    byte[] encVal = cipher.doFinal(data.getBytes()); 
    byte[] finalByte=copyBytes(encVal, ivAES); 
    String encryptedValue = new BASE64Encoder().encode(finalByte); 
    return encryptedValue; 
    } 

    public static String decrypt(String encryptedData,String secretKey) throws Exception { 
    Key key = generateKey(secretKey); 
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData); 
    ArrayList<byte[]> al = retreiveIv(decordedValue); 
    byte[] data = al.get(0); 
    byte[] iv = al.get(1); 
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
    cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); 

    byte[] decValue = cipher.doFinal(data); 
    String decryptedValue = new String(decValue); 
    return decryptedValue; 
    } 

    private static Key generateKey(String secretKey) throws Exception { 
    Key key = new SecretKeySpec(secretKey.getBytes(), ALGO); 
    return key; 
    } 
    private static byte[] copyBytes(byte[] encVal, byte[] iv) throws Exception { 
     ByteArrayOutputStream os = new ByteArrayOutputStream(); 
     os.write(iv); 
     os.write(encVal); 
     return os.toByteArray(); 
    } 
    private static ArrayList<byte[]> retreiveIv(byte[] combineByte) { 
     ByteArrayOutputStream iv = new ByteArrayOutputStream(16); 
     ByteArrayOutputStream data = new ByteArrayOutputStream(); 

     data.write(combineByte, combineByte.length - 16, 16); 
     iv.write(combineByte, 0, combineByte.length - 16); 

     ArrayList<byte[]> al = new ArrayList<byte[]>(); 
     al.add(data.toByteArray()); 
     al.add(iv.toByteArray()); 

     return al; 
    } 

    public static void main(String[] args) throws Exception{ 


     System.out.println(AESUtil.decrypt(AESUtil.encrypt("Hello", "AVH4TU8AC99dhL2l"), "AVH4TU8AC99dhL2l")); 

} 


} 

復号化(のDataPower)

<xsl:variable name="algorithm">http://www.w3.org/2001/04/xmlenc#aes128-cbc</xsl:variable> 

<xsl:variable name="decryptOut"><xsl:value-of select="dp:decrypt-data($algorithm,'name:danadp',$valueToDecrypt)"/></xsl:variable>  
Decrypted Value: <xsl:copy-of select="$decryptOut"/> 

しかし、私たちは、暗号化のためのJavaコードで生成されたのDataPowerの鍵オブジェクトを共有する方法を得ていないのです。

誰でも私を助けることができればそれは素晴らしいことでしょう。

答えて

0

名前が「danadp」で、鍵がファイルにコピーされ、このコードが実行されているDataPowerドメインのcert:/フォルダにインポートされた共有秘密鍵オブジェクトを作成します。

P.Sキーが16進数である場合は、キーの前に "0x"を付けてください。

関連する問題