kettle 数据加密

kettle传输数据如何加密

九三
1142
2021-01-20 14:02:46
栏目: 网络安全

kettle传输数据如何加密

java使用ASE128对kettle加密传输数据,具体方法如下:

package com;

import javax.crypto.Cipher;

import javax.crypto.spec.IvParameterSpec;

import javax.crypto.spec.SecretKeySpec;

import sun.misc.BASE64Decoder;

import sun.misc.BASE64Encoder;

public class AES128 {

private static String sKey = "6d782000a3625132";

private static String ivParameter = "66692k0da001d091";

private static AES128 instance = null;

private AES128() {

}

public static AES128 getInstance() {

if (instance == null)

instance = new AES128();

return instance;

}

// 加密

public static String encrypt(String sSrc, String encodingFormat,String sKey, String ivParameter) throws Exception {

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

byte[] raw = sKey.getBytes();

SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");

// 使用CBC模式,需要一个向量iv,可增加加密算法的强度

IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());

cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);

byte[] encrypted = cipher.doFinal(sSrc.getBytes(encodingFormat));

// 此处使用BASE64做转码。

return new BASE64Encoder().encode(encrypted);

}

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

// 需要加密的字串

String cSrc = "12026198505162431";

System.out.println("加密前的字串是:" + cSrc);

// 加密

long lStart = System.currentTimeMillis();

String enString = AES128.getInstance().encrypt(cSrc, "utf-8", sKey,ivParameter);

System.out.println("加密后的字串是:" + enString);

long lUseTime = System.currentTimeMillis() - lStart;

System.out.println("加密耗时:" + lUseTime + "毫秒");

}

0
看了该问题的人还看了