修改中文乱码,测试接口
This commit is contained in:
parent
0029fa1c26
commit
b65f76aab8
@ -3,6 +3,8 @@ package com.sunyard.inf;
|
||||
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
|
||||
import com.sunyard.RetWrap;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 对称加解密相关接口
|
||||
*/
|
||||
@ -300,7 +302,7 @@ interface SydSYMApi {
|
||||
* @param outFilePath 解密后的数据文件所在的路径
|
||||
* @return 解密是否成功。false为失败,true为成功
|
||||
*/
|
||||
boolean SM4DecryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath);
|
||||
boolean SM4DecryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 使用SM4算法进行解密,其中加密模式为CBC,
|
||||
|
||||
@ -65,9 +65,9 @@ public class FileUtil {
|
||||
* @param data 数据
|
||||
*/
|
||||
public static void printDataToFile(String path, String data) {
|
||||
OutputStreamWriter osw = null;
|
||||
BufferedWriter osw = null;
|
||||
try {
|
||||
osw = new OutputStreamWriter(new FileOutputStream(path));
|
||||
osw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
|
||||
|
||||
osw.write(data);
|
||||
|
||||
|
||||
@ -1608,7 +1608,7 @@ public class SydApi4j implements SydApi {
|
||||
iv = niv;
|
||||
//存储iv
|
||||
retWrap.put("iv", iv);
|
||||
System.out.println("下一iv长度:" + iv.length);
|
||||
// System.out.println("下一iv长度:" + iv.length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4318,7 +4318,7 @@ public class SydApi4j implements SydApi {
|
||||
*/
|
||||
// 测试通过
|
||||
@Override
|
||||
public boolean SM4DecryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath) {
|
||||
public boolean SM4DecryptFileDataCBC(int keyType, String key, int inType, int outType, String inFilePath, String outFilePath) throws UnsupportedEncodingException {
|
||||
|
||||
byte[] msg = FileUtil.getDataFromFile(inFilePath);
|
||||
|
||||
@ -4329,7 +4329,7 @@ public class SydApi4j implements SydApi {
|
||||
// 调用加密接口将数据加密
|
||||
byte[] result = SM4DecryptDataCBC(keyType, key, inType, outType, Util.hexString2Bytes(new String(msg)));
|
||||
|
||||
String str = new String(Util.hexString2Bytes(Util.bytes2HexString(result)));
|
||||
String str = new String(result, "utf-8");
|
||||
|
||||
FileUtil.printDataToFile(outFilePath, str);
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printByteArray;
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
@ -146,7 +148,7 @@ public class ABCNorthBranch {
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4DecryptFileDataCBC() {
|
||||
public void testSM4DecryptFileDataCBC() throws UnsupportedEncodingException {
|
||||
|
||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
||||
String outFilePath2 = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\out1.txt";
|
||||
|
||||
@ -663,7 +663,7 @@ public class TestAllMethods {
|
||||
// 测试通过
|
||||
// E0
|
||||
@Test
|
||||
public void testSM4DecryptFileDataCBC() {
|
||||
public void testSM4DecryptFileDataCBC() throws UnsupportedEncodingException {
|
||||
String key = "X6CEE744329499B426CEE744329499B42";
|
||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
||||
String outFilePath2 = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\out1.txt";
|
||||
@ -671,6 +671,19 @@ public class TestAllMethods {
|
||||
System.out.println(b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testaaa() throws UnsupportedEncodingException {
|
||||
String key = "X6CEE744329499B426CEE744329499B42";
|
||||
String inFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in1.txt";
|
||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
||||
String outFilePath2 = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\out1.txt";
|
||||
|
||||
boolean b = api.SM4EncryptFileDataCBC(0, key, 0, 0, inFilePath, outFilePath);
|
||||
System.out.println(b);
|
||||
boolean c = api.SM4DecryptFileDataCBC(0, key, 0, 0, outFilePath, outFilePath2);
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// Y0
|
||||
@Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user