kettle传输数据如何加密

1689
2021/1/20 14:02:46
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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 + "毫秒");

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: linux中kettle如何开启和关闭