import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyStore; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManagerFactory; import cfca.seal.util.Base64;
import cfca.seal.util.StringUtil; public class SealClient
{
public static final String ASSIST_SEAL_SERVLET = "AssistSealServlet";
public static final String MAKE_SEAL_SERVLET = "MakeSealServlet";
public static final String WEB_SEAL_SERVLET = "WebSealServlet";
public static final String PDF_SEAL_SERVLET = "PdfSealServlet";
public static final String BUSINESS_SEAL_SERVLET = "BusinessSealServlet";
public static final String DEFAULT_CHARSET = "UTF-8";
public static final String SLASH = "/";
private String urlString;
private int connectTimeout = 30000;
private int readTimeout = 30000; private String keyStorePath = "";
private String keyStorePassword = "";
private String trustStorePath = "";
private String trustStorePassword = ""; public SealClient(String urlString, String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword) {
this.keyStorePath = keyStorePath;
this.keyStorePassword = keyStorePassword;
this.trustStorePath = trustStorePath;
this.trustStorePassword = trustStorePassword;
this.urlString = urlString;
} public SealClient(String urlString) {
this.urlString = urlString;
} public SealClient(String urlString, int connectTimeout, int readTimeout) {
this.urlString = urlString;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
} public String reqAndRes(String urlString, String parameterData) throws Exception {
String result = ""; if ((StringUtil.isNotEmpty(urlString)) && (urlString.startsWith("https://")))
result = reqAndResForHttps(urlString, parameterData);
else if ((StringUtil.isNotEmpty(urlString)) && (urlString.startsWith("http://"))) {
result = reqAndResForHttp(urlString, parameterData);
} return result;
} public String reqAndResForHttps(String urlString, String parameterData) throws Exception
{
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
StringBuffer resultBuffer = new StringBuffer();
try
{
SSLContext sslContext = getSSLContext(this.keyStorePath, this.keyStorePassword, this.trustStorePath, this.trustStorePassword);
URL url = new URL(urlString);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setSSLSocketFactory(sslContext.getSocketFactory());
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(this.connectTimeout));
System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(this.readTimeout));
conn.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
conn.setRequestProperty("Content-Length", String.valueOf(parameterData.length()));
outputStream = conn.getOutputStream(); outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(parameterData);
outputStreamWriter.flush(); inputStream = conn.getInputStream();
inputStreamReader = new InputStreamReader(inputStream);
reader = new BufferedReader(inputStreamReader);
String tempLine = null;
while ((tempLine = reader.readLine()) != null)
resultBuffer.append(tempLine);
}
catch (MalformedURLException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
if (outputStreamWriter != null) {
outputStreamWriter.close();
} if (outputStream != null) {
outputStream.close();
} if (reader != null) {
reader.close();
} if (inputStreamReader != null) {
inputStreamReader.close();
} if (inputStream != null) {
inputStream.close();
}
}
return resultBuffer.toString();
} public String reqAndResForHttp(String urlString, String parameterData) throws Exception {
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
StringBuffer resultBuffer = new StringBuffer();
try
{
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(parameterData.length()));
System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(this.connectTimeout));
System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(this.readTimeout));
outputStream = conn.getOutputStream();
outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(parameterData);
outputStreamWriter.flush();
inputStream = conn.getInputStream();
inputStreamReader = new InputStreamReader(inputStream);
reader = new BufferedReader(inputStreamReader);
String tempLine = null;
while ((tempLine = reader.readLine()) != null)
resultBuffer.append(tempLine);
}
catch (MalformedURLException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
if (outputStreamWriter != null) {
outputStreamWriter.close();
} if (outputStream != null) {
outputStream.close();
} if (reader != null) {
reader.close();
} if (inputStreamReader != null) {
inputStreamReader.close();
} if (inputStream != null) {
inputStream.close();
}
}
return resultBuffer.toString();
} public SSLContext getSSLContext(String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword) throws Exception
{
SSLContext ctx = SSLContext.getInstance("SSL"); String jdkvs = System.getProperty("java.vm.vendor"); KeyManagerFactory kmf = null;
TrustManagerFactory tmf = null;
if ((null != jdkvs) && (jdkvs.startsWith("IBM"))) {
kmf = KeyManagerFactory.getInstance("IbmX509");
tmf = TrustManagerFactory.getInstance("IbmPKIX");
} else {
kmf = KeyManagerFactory.getInstance("SunX509");
tmf = TrustManagerFactory.getInstance("SunX509");
} KeyStore ks = null; if (keyStorePath.indexOf("jks") >= 0)
ks = KeyStore.getInstance("JKS");
else if (keyStorePath.indexOf("pfx") >= 0) {
ks = KeyStore.getInstance("PKCS12");
}
KeyStore tks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(keyStorePath), keyStorePassword.toCharArray());
tks.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray()); kmf.init(ks, keyStorePassword.toCharArray());
tmf.init(tks); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); return ctx;
} public String makeSeal(byte[] pfx, String pfxPassword, byte[] image, String sealInfoXML)
throws Exception
{
try
{
String pfxString = new String(Base64.encode(pfx), "UTF-8");
pfxString = URLEncoder.encode(pfxString, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); String imageString = new String(Base64.encode(image), "UTF-8");
imageString = URLEncoder.encode(imageString, "UTF-8"); sealInfoXML = new String(Base64.encode(sealInfoXML.getBytes("UTF-8")), "UTF-8");
sealInfoXML = URLEncoder.encode(sealInfoXML, "UTF-8"); String parameterData = "type=makeSeal&pfx=" + pfxString + "&pfxPassword=" + pfxPassword + "&image=" + imageString + "&sealInfoXML=" + sealInfoXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String makeNamedSeal(byte[] pfx, String pfxPassword, String sealInfoXML)
throws Exception
{
try
{
String pfxString = new String(Base64.encode(pfx), "UTF-8");
pfxString = URLEncoder.encode(pfxString, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); sealInfoXML = new String(Base64.encode(sealInfoXML.getBytes("UTF-8")), "UTF-8");
sealInfoXML = URLEncoder.encode(sealInfoXML, "UTF-8"); String parameterData = "type=makeNamedSeal&pfx=" + pfxString + "&pfxPassword=" + pfxPassword + "&sealInfoXML=" + sealInfoXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String updateSeal(byte[] pfx, String pfxPassword, byte[] image, String sealInfoXML)
throws Exception
{
try
{
String pfxString = new String(Base64.encode(pfx), "UTF-8");
pfxString = URLEncoder.encode(pfxString, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); String imageString = new String(Base64.encode(image), "UTF-8");
imageString = URLEncoder.encode(imageString, "UTF-8"); sealInfoXML = new String(Base64.encode(sealInfoXML.getBytes("UTF-8")), "UTF-8");
sealInfoXML = URLEncoder.encode(sealInfoXML, "UTF-8"); String parameterData = "type=updateSeal&pfx=" + pfxString + "&pfxPassword=" + pfxPassword + "&image=" + imageString + "&sealInfoXML=" + sealInfoXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String updateNamedSeal(byte[] pfx, String pfxPassword, String sealInfoXML)
throws Exception
{
try
{
String pfxString = new String(Base64.encode(pfx), "UTF-8");
pfxString = URLEncoder.encode(pfxString, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); sealInfoXML = new String(Base64.encode(sealInfoXML.getBytes("UTF-8")), "UTF-8");
sealInfoXML = URLEncoder.encode(sealInfoXML, "UTF-8"); String parameterData = "type=updateNamedSeal&pfx=" + pfxString + "&pfxPassword=" + pfxPassword + "&sealInfoXML=" + sealInfoXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] sealAutoPdf(byte[] pdf, String sealStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8");
sealStrategyXML = new String(Base64.encode(sealStrategyXML.getBytes("UTF-8")), "UTF-8");
sealStrategyXML = URLEncoder.encode(sealStrategyXML, "UTF-8"); String parameterData = "type=sealAutoPdf&pdf=" + pdfString + "&sealStrategyXML=" + sealStrategyXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] batchSealAutoPdf(byte[] pdf, String batchSealStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); batchSealStrategyXML = new String(Base64.encode(batchSealStrategyXML.getBytes("UTF-8")), "UTF-8");
batchSealStrategyXML = URLEncoder.encode(batchSealStrategyXML, "UTF-8"); String parameterData = "type=batchSealAutoPdf&pdf=" + pdfString + "&batchSealStrategyXML=" + batchSealStrategyXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String sealBase64PdfFunction(String pdfBase64, String pfxBase64, String pfxPassword, String imageBase64, String sealFunctionStrategyXML)
throws Exception
{
try
{
pdfBase64 = new String(Base64.encode(pdfBase64.getBytes("UTF-8")), "UTF-8");
pdfBase64 = URLEncoder.encode(pdfBase64, "UTF-8"); pfxBase64 = new String(Base64.encode(pfxBase64.getBytes("UTF-8")), "UTF-8");
pfxBase64 = URLEncoder.encode(pfxBase64, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); imageBase64 = new String(Base64.encode(imageBase64.getBytes("UTF-8")), "UTF-8");
imageBase64 = URLEncoder.encode(imageBase64, "UTF-8"); sealFunctionStrategyXML = new String(Base64.encode(sealFunctionStrategyXML.getBytes("UTF-8")), "UTF-8");
sealFunctionStrategyXML = URLEncoder.encode(sealFunctionStrategyXML, "UTF-8"); String parameterData = "type=sealBase64PdfFunction&pdfBase64=" + pdfBase64 + "&pfxBase64=" + pfxBase64 + "&pfxPassword=" + pfxPassword + "&imageBase64=" + imageBase64 + "&sealFunctionStrategyXML=" + sealFunctionStrategyXML; return reqAndRes(this.urlString, parameterData);
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
} public byte[] sealPdfFunction(byte[] pdf, byte[] pfx, String pfxPassword, byte[] image, String sealFunctionStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); String pfxString = new String(Base64.encode(pfx), "UTF-8");
pfxString = URLEncoder.encode(pfxString, "UTF-8"); pfxPassword = new String(Base64.encode(pfxPassword.getBytes("UTF-8")), "UTF-8");
pfxPassword = URLEncoder.encode(pfxPassword, "UTF-8"); String imageString = new String(Base64.encode(image), "UTF-8");
imageString = URLEncoder.encode(imageString, "UTF-8"); sealFunctionStrategyXML = new String(Base64.encode(sealFunctionStrategyXML.getBytes("UTF-8")), "UTF-8");
sealFunctionStrategyXML = URLEncoder.encode(sealFunctionStrategyXML, "UTF-8"); String parameterData = "type=sealPdfFunction&pdfString=" + pdfString + "&pfxString=" + pfxString + "&pfxPassword=" + pfxPassword + "&imageString=" + imageString + "&sealFunctionStrategyXML=" + sealFunctionStrategyXML; return Base64.decode(reqAndRes(this.urlString, parameterData));
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
} public byte[] sealAutoCrossPdf(byte[] pdf, String crossSealStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); crossSealStrategyXML = new String(Base64.encode(crossSealStrategyXML.getBytes("UTF-8")), "UTF-8");
crossSealStrategyXML = URLEncoder.encode(crossSealStrategyXML, "UTF-8"); String parameterData = "type=sealAutoCrossPdf&pdf=" + pdfString + "&crossSealStrategyXML=" + crossSealStrategyXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] sealAutoSynthesizedBusinessPdf(byte[] pdf, String businessXML, String sealStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); businessXML = new String(Base64.encode(businessXML.getBytes("UTF-8")), "UTF-8");
businessXML = URLEncoder.encode(businessXML, "UTF-8"); sealStrategyXML = new String(Base64.encode(sealStrategyXML.getBytes("UTF-8")), "UTF-8");
sealStrategyXML = URLEncoder.encode(sealStrategyXML, "UTF-8"); String parameterData = "type=sealAutoSynthesizedBusinessPdf&pdf=" + pdfString + "&businessXML=" + businessXML + "&sealStrategyXML=" + sealStrategyXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] addWaterMark2Pdf(byte[] pdf, String waterMarkStrategyXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); waterMarkStrategyXML = new String(Base64.encode(waterMarkStrategyXML.getBytes("UTF-8")), "UTF-8");
waterMarkStrategyXML = URLEncoder.encode(waterMarkStrategyXML, "UTF-8"); String parameterData = "type=addWaterMark2Pdf&pdf=" + pdfString + "&waterMarkStrategyXML=" + waterMarkStrategyXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] signWebSeal(String sourceBase64, String sealStrategyXml)
throws Exception
{
try
{
sourceBase64 = new String(Base64.encode(sourceBase64.getBytes("UTF-8")), "UTF-8");
sourceBase64 = URLEncoder.encode(sourceBase64, "UTF-8"); sealStrategyXml = new String(Base64.encode(sealStrategyXml.getBytes("UTF-8")), "UTF-8");
sealStrategyXml = URLEncoder.encode(sealStrategyXml, "UTF-8"); String parameterData = "type=signWebSeal&sourceBase64=" + sourceBase64 + "&sealStrategyXml=" + sealStrategyXml; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String verifyPdfSeal(byte[] sealedPdf, String verifyStrategyXML)
throws Exception
{
try
{
String sealedPdfString = new String(Base64.encode(sealedPdf), "UTF-8");
sealedPdfString = URLEncoder.encode(sealedPdfString, "UTF-8"); verifyStrategyXML = new String(Base64.encode(verifyStrategyXML.getBytes("UTF-8")), "UTF-8");
verifyStrategyXML = URLEncoder.encode(verifyStrategyXML, "UTF-8"); String parameterData = "type=verifyPdfSeal&sealedPdf=" + sealedPdfString + "&verifyStrategyXML=" + verifyStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String verifyWebSeal(String webSealSource, String sourceBase64, String verifyStrategyXML)
throws Exception
{
try
{
webSealSource = new String(Base64.encode(webSealSource.getBytes("UTF-8")), "UTF-8");
webSealSource = URLEncoder.encode(webSealSource, "UTF-8"); sourceBase64 = new String(Base64.encode(sourceBase64.getBytes("UTF-8")), "UTF-8");
sourceBase64 = URLEncoder.encode(sourceBase64, "UTF-8"); verifyStrategyXML = new String(Base64.encode(verifyStrategyXML.getBytes("UTF-8")), "UTF-8");
verifyStrategyXML = URLEncoder.encode(verifyStrategyXML, "UTF-8"); String parameterData = "type=verifyWebSeal&webSealSource=" + webSealSource + "&sourceBase64=" + sourceBase64 + "&verifyStrategyXML=" + verifyStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] synthesizeAutoBusinessPdf(byte[] pdf, String businessXML)
throws Exception
{
try
{
String pdfString = new String(Base64.encode(pdf), "UTF-8");
pdfString = URLEncoder.encode(pdfString, "UTF-8"); businessXML = new String(Base64.encode(businessXML.getBytes("UTF-8")), "UTF-8");
businessXML = URLEncoder.encode(businessXML, "UTF-8"); String parameterData = "type=synthesizeAutoBusinessPdf&pdf=" + pdfString + "&businessXML=" + businessXML; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public byte[] transformToPdf(byte[] source, String fileType)
throws Exception
{
try
{
String sourceString = new String(Base64.encode(source), "UTF-8");
sourceString = URLEncoder.encode(sourceString, "UTF-8"); fileType = new String(Base64.encode(fileType.getBytes("UTF-8")), "UTF-8");
fileType = URLEncoder.encode(fileType, "UTF-8"); String parameterData = "type=transformToPdf&sourceString=" + sourceString + "&fileType=" + fileType; String resultString = reqAndRes(this.urlString, parameterData);
return Base64.decode(resultString.getBytes("UTF-8"));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String p1Sign(byte[] source, String signStrategyXML)
throws Exception
{
try
{
String sourceString = new String(Base64.encode(source), "UTF-8");
sourceString = URLEncoder.encode(sourceString, "UTF-8"); signStrategyXML = new String(Base64.encode(signStrategyXML.getBytes("UTF-8")), "UTF-8");
signStrategyXML = URLEncoder.encode(signStrategyXML, "UTF-8"); String parameterData = "type=p1Sign&source=" + sourceString + "&signStrategyXML=" + signStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String p7SignDetached(byte[] source, String signStrategyXML)
throws Exception
{
try
{
String sourceString = new String(Base64.encode(source), "UTF-8");
sourceString = URLEncoder.encode(sourceString, "UTF-8"); signStrategyXML = new String(Base64.encode(signStrategyXML.getBytes("UTF-8")), "UTF-8");
signStrategyXML = URLEncoder.encode(signStrategyXML, "UTF-8"); String parameterData = "type=p7SignDetached&source=" + sourceString + "&signStrategyXML=" + signStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String p7VerifyDetached(String signatureBase64, byte[] source, String verifyStrategyXML)
throws Exception
{
try
{
signatureBase64 = new String(Base64.encode(signatureBase64.getBytes("UTF-8")), "UTF-8");
signatureBase64 = URLEncoder.encode(signatureBase64, "UTF-8"); String sourceString = new String(Base64.encode(source), "UTF-8");
sourceString = URLEncoder.encode(sourceString, "UTF-8"); verifyStrategyXML = new String(Base64.encode(verifyStrategyXML.getBytes("UTF-8")), "UTF-8");
verifyStrategyXML = URLEncoder.encode(verifyStrategyXML, "UTF-8"); String parameterData = "type=p7VerifyDetached&signatureBase64=" + signatureBase64 + "&source=" + sourceString + "&verifyStrategyXML=" + verifyStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String getSealInfo(String sealCode)
throws Exception
{
try
{
sealCode = new String(Base64.encode(sealCode.getBytes("UTF-8")), "UTF-8");
sealCode = URLEncoder.encode(sealCode, "UTF-8"); String parameterData = "type=getSealInfo&sealCode=" + sealCode; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String bindSeal(String bindSealXML)
throws Exception
{
try
{
bindSealXML = new String(Base64.encode(bindSealXML.getBytes("UTF-8")), "UTF-8");
bindSealXML = URLEncoder.encode(bindSealXML, "UTF-8"); String parameterData = "type=bindSeal&bindSealXML=" + bindSealXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} public String autoGenerateImage(String imageStrategyXML)
throws Exception
{
try
{
imageStrategyXML = new String(Base64.encode(imageStrategyXML.getBytes("UTF-8")), "UTF-8");
imageStrategyXML = URLEncoder.encode(imageStrategyXML, "UTF-8"); String parameterData = "type=autoGenerateImage&imageStrategyXML=" + imageStrategyXML; String resultString = reqAndRes(this.urlString, parameterData); return new String(Base64.decode(resultString.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}

SealClient的更多相关文章

随机推荐

  1. docker容器中布置静态网站

    docker容器中布置静态网站(基于云服务器ubuntu系统) 服务器准备(ubuntu) docker nginx 静态网页制作 浏览器测试 服务器布置 这里推荐使用云服务器(阿里云.华为云.腾讯云 ...

  2. .NET 云原生架构师训练营(模块二 基础巩固 MongoDB 问答系统)--学习笔记

    2.5.6 MongoDB -- 问答系统 MongoDB 数据库设计 API 实现概述 MongoDB 数据库设计 设计优化 内嵌(mongo)还是引用(mysql) 数据一致性 范式:将数据分散到 ...

  3. 上传功能-弹窗实现-vue

    -引入弹窗页面 import fileUpload from 'src/page/cuApplyManage/fileUpload.vue'; -页面布局 <div> <fileUp ...

  4. 2021升级版微服务教程3—Eureka完全使用指南

    2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 默认文件1610014380163 教程全目录「含视 ...

  5. 【C++】《C++ Primer 》第十五章

    第十五章 面向对象程序设计 一.OOP:概述 面向对象程序设计(OOP)的核心思想是数据抽象.继承和动态绑定. 通过使用数据抽象,可以将类的接口和实现分离. 使用继承,可以定义相似的类型并对其相似关系 ...

  6. Linux Bash Shell常用快捷键

    Linux Bash Shell常用快捷键 table { margin: auto } 快捷键 功能 tab 补全 ctrl + a 光标回到命令行首 ctrl + e 光标回到命令行尾 ctrl ...

  7. Java编译期注解处理器详细使用方法

    目录 Java编译期注解处理器 启用注解处理器 遍历语法树 语法树中的源节点 语法树节点的操作 给类增加注解 给类增加import语句 构建一个内部类 使用方法 chainDots方法 总结 Java ...

  8. HTML&CSS:构建网站不能不说的那些事儿

    很高兴你能看到这个专栏!俗话说得好,相逢即是缘分,没准你和我在上一世也曾有过五百次的回眸,才得此一面.说的有点恶心了,咱还是书归正传,说说这个专栏吧. 这个专栏主要讲的是 HTML 和 CSS 的页面 ...

  9. pycharm工具的使用

    一.Pycharm常用快捷键 快捷键 作用 备注  ctrl + win + 空格  自动提示并导包  连按两次  ctrl + alt + 空格  自动提示并导包  连按两次  Alt + Ente ...

  10. 记一次 RocketMQ broker 因内存不足导致的启动失败

    原创:西狩 编写日期 / 修订日期:2020-01-12 / 2020-01-12 版权声明:本文为博主原创文章,遵循 CC BY-SA-4.0 版权协议,转载请附上原文出处链接和本声明. 背景 该小 ...