Search in sources :

Example 31 with BASE64Decoder

use of sun.misc.BASE64Decoder in project portal by ixinportal.

the class ReceiptTest method test.

@Test
public void test() {
    // 正式系统地址
    String url = "https://www.fapiao.com:53087/fpt-dsqz/services/DZFPService";
    // String appId = "0d94a610c6e9a4260201b003bd78bdf8981af7906e4da43b96435bfaee4a089f"; //appid
    String appId = "2550ac3d539f7db6f859485af99e63de9882514145fbc2199d3f65f3bfece980";
    // String url = "https://dev.fapiao.com:19443/fpt-dsqz-spbm/services/DZFPService"; //测试地址
    // String appId = "6d29f136114544bcc73edcce960c430231183cc192c433e2b9ebcad56e8ceb08"; //appid
    // 执行命令后,会生成该testclient.truststore
    String ssl_store = getClass().getClassLoader().getResource("").getPath() + File.separator + "fapiao.truststore";
    // 证书的存取密码,即执行命令时填写的密码
    String ssl_pwd = "ixin21060921";
    System.setProperty("javax.net.ssl.trustStore", ssl_store);
    System.setProperty("javax.net.ssl.keyStorePassword", ssl_pwd);
    HostnameVerifier hv = new HostnameVerifier() {

        public boolean verify(String urlHostName, SSLSession session) {
            System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    try {
        org.apache.axis.client.Service s = new org.apache.axis.client.Service();
        Call call = (Call) s.createCall();
        call.setTargetEndpointAddress(new URL(url));
        call.setOperation("doService");
        String content;
        String xml;
        String val;
        Map<String, String> temp;
        Long count = 0L;
        // 循环开票数量
        for (int i = 0; i < 0; i++) {
            count++;
            content = getContent(count);
            log.error("[input0]{}", content);
            xml = getCommonXml("DFXJ1001", new BASE64Encoder().encodeBuffer(content.getBytes("UTF-8")), appId);
            log.error("[input1]{}", xml);
            Object[] fn01 = { xml };
            val = (String) call.invoke(fn01);
            log.error("[output]{}", val);
            temp = parseXml(val);
            if (!temp.get("returnCode").equals("0000")) {
                log.error("ERRORLOG电子发票 {}", "开票推送失败,错误:" + temp.get("returnMessage"));
            }
            temp = parseXml(new String(new BASE64Decoder().decodeBuffer(temp.get("content")), "UTF-8"));
            log.error("pefurl=" + temp.get("PDF_URL"));
        }
    } catch (Exception e) {
        log.error("ERRORLOG电子发票 {}", "开票推送失败,错误:" + e.toString());
        e.printStackTrace();
    }
}
Also used : Call(org.apache.axis.client.Call) BASE64Encoder(sun.misc.BASE64Encoder) SSLSession(javax.net.ssl.SSLSession) AuthService(com.itrus.portal.evidence.controller.threeAppAPIService.AuthService) URL(java.net.URL) IOException(java.io.IOException) HostnameVerifier(javax.net.ssl.HostnameVerifier) JSONObject(com.alibaba.fastjson.JSONObject) BASE64Decoder(sun.misc.BASE64Decoder) Test(org.junit.Test)

Example 32 with BASE64Decoder

use of sun.misc.BASE64Decoder in project javautils by jiadongpo.

the class RSAUtil method fileDecrypt.

/**
 * 使用keystore对密文进行解密
 * @param privateKeystore  私钥路径
 * @param enStr            密文
 * @return
 */
public static String fileDecrypt(String privateKeystore, String enStr) {
    try {
        FileReader fr = new FileReader(privateKeystore);
        BufferedReader br = new BufferedReader(fr);
        String privateKeyString = "";
        String str;
        while ((str = br.readLine()) != null) {
            privateKeyString += str;
        }
        br.close();
        fr.close();
        cipher.init(Cipher.DECRYPT_MODE, getPrivateKey(privateKeyString));
        byte[] deBytes = cipher.doFinal((new BASE64Decoder()).decodeBuffer(enStr));
        return new String(deBytes);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : BufferedReader(java.io.BufferedReader) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) FileReader(java.io.FileReader) BadPaddingException(javax.crypto.BadPaddingException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) BASE64Decoder(sun.misc.BASE64Decoder) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IOException(java.io.IOException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 33 with BASE64Decoder

use of sun.misc.BASE64Decoder in project javautils by jiadongpo.

the class RSAUtil method decrypt.

/**
 * 使用私钥对密文进行解密
 * @param privateKey       私钥
 * @param enStr            密文
 * @return
 */
public static String decrypt(String privateKey, String enStr) {
    try {
        cipher.init(Cipher.DECRYPT_MODE, getPrivateKey(privateKey));
        byte[] deBytes = cipher.doFinal((new BASE64Decoder()).decodeBuffer(enStr));
        return new String(deBytes);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) BadPaddingException(javax.crypto.BadPaddingException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) BASE64Decoder(sun.misc.BASE64Decoder) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IOException(java.io.IOException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 34 with BASE64Decoder

use of sun.misc.BASE64Decoder in project vip by guangdada.

the class MD5 method t.

public static void t() {
    String sql = "OezXcEiiBSKSxW0eoylIeP0vrZKNUFaiKCV7NbFjnJu6goFepR6kzZc5NTN--2I-fHckWCS03u4Zs8uy-xtwLp0gh53Zd_Lp3gyFGr0Yh_QucXrs8PsCxFBtFyPyWhmyGHtLK6BcnKXkRVRPmBq0oA";
    getTI(sql);
    BASE64Decoder dc = new BASE64Decoder();
    try {
        byte[] bt = dc.decodeBuffer(sql);
        System.out.println(new String(bt, "gbk"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder)

Example 35 with BASE64Decoder

use of sun.misc.BASE64Decoder in project archi-modelrepository-plugin by archi-contribs.

the class SimpleCredentialsStorage method decrypt.

public static String decrypt(String encstr) throws IOException {
    if (encstr.length() > 12) {
        String cipher = encstr.substring(12);
        BASE64Decoder decoder = new BASE64Decoder();
        return new String(decoder.decodeBuffer(cipher));
    }
    return null;
}
Also used : BASE64Decoder(sun.misc.BASE64Decoder)

Aggregations

BASE64Decoder (sun.misc.BASE64Decoder)44 IOException (java.io.IOException)23 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 OutputStream (java.io.OutputStream)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JSONObject (com.alibaba.fastjson.JSONObject)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 BASE64Encoder (sun.misc.BASE64Encoder)4 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)3 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 KeyFactory (java.security.KeyFactory)3 CertificateException (java.security.cert.CertificateException)3 Map (java.util.Map)3 Cipher (javax.crypto.Cipher)3