Search in sources :

Example 6 with BASE64Decoder

use of sun.misc.BASE64Decoder in project HawkEye by oliverwoodings.

the class SignEntry method interpretSqlData.

@Override
public void interpretSqlData(String data) {
    if (data.indexOf("@") == -1)
        return;
    String[] arr = data.split("@");
    //Parse wall sign or not
    if (arr[0].equals("true"))
        wallSign = true;
    else
        wallSign = false;
    //Parse sign direction
    for (BlockFace face : BlockFace.values()) if (face.toString().equalsIgnoreCase(arr[1]))
        facing = face;
    //Parse lines
    if (arr.length != 3)
        return;
    BASE64Decoder decoder = new BASE64Decoder();
    List<String> decoded = new ArrayList<String>();
    String[] encLines = arr[2].split(",");
    for (int i = 0; i < encLines.length; i++) {
        try {
            decoded.add(new String(decoder.decodeBuffer(encLines[i])));
        } catch (IOException e) {
            Util.severe("Unable to decode sign data from database");
        }
    }
    lines = decoded.toArray(new String[0]);
}
Also used : BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder)

Example 7 with BASE64Decoder

use of sun.misc.BASE64Decoder in project intellij-community by JetBrains.

the class IpnbImagePanel method createViewPanel.

@Override
protected JComponent createViewPanel() {
    final String png = myCell.getBase64String();
    final JBLabel label = new JBLabel();
    if (!StringUtil.isEmptyOrSpaces(png)) {
        try {
            byte[] btDataFile = new BASE64Decoder().decodeBuffer(png);
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(btDataFile));
            label.setIcon(new ImageIcon(image));
        } catch (Exception e) {
            LOG.error("Couldn't parse image. " + e.getMessage());
        }
    }
    label.setBackground(IpnbEditorUtil.getBackground());
    label.setOpaque(true);
    return label;
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) ByteArrayInputStream(java.io.ByteArrayInputStream) BASE64Decoder(sun.misc.BASE64Decoder) BufferedImage(java.awt.image.BufferedImage)

Example 8 with BASE64Decoder

use of sun.misc.BASE64Decoder in project jdk8u_jdk by JetBrains.

the class TestBase64Golden method test0.

public static void test0(Base64Type type, Encoder encoder, Decoder decoder, String srcFile, String encodedFile) throws Exception {
    String[] srcLns = Files.readAllLines(Paths.get(SRCDIR, srcFile), DEF_CHARSET).toArray(new String[0]);
    String[] encodedLns = Files.readAllLines(Paths.get(SRCDIR, encodedFile), DEF_CHARSET).toArray(new String[0]);
    int lns = 0;
    for (String srcStr : srcLns) {
        String encodedStr = null;
        if (type != Base64Type.MIME) {
            encodedStr = encodedLns[lns++];
        } else {
            while (lns < encodedLns.length) {
                String s = encodedLns[lns++];
                if (s.length() == 0)
                    break;
                if (encodedStr != null) {
                    encodedStr += DEFAULT_CRLF + s;
                } else {
                    encodedStr = s;
                }
            }
            if (encodedStr == null && srcStr.length() == 0) {
                encodedStr = "";
            }
        }
        System.out.printf("%n    src[%d]: %s%n", srcStr.length(), srcStr);
        System.out.printf("encoded[%d]: %s%n", encodedStr.length(), encodedStr);
        byte[] srcArr = srcStr.getBytes(DEF_CHARSET);
        byte[] encodedArr = encodedStr.getBytes(DEF_CHARSET);
        ByteBuffer srcBuf = ByteBuffer.wrap(srcArr);
        ByteBuffer encodedBuf = ByteBuffer.wrap(encodedArr);
        byte[] resArr = new byte[encodedArr.length];
        // test int encode(byte[], byte[])
        int len = encoder.encode(srcArr, resArr);
        assertEqual(len, encodedArr.length);
        assertEqual(resArr, encodedArr);
        // test byte[] encode(byte[])
        resArr = encoder.encode(srcArr);
        assertEqual(resArr, encodedArr);
        // test ByteBuffer encode(ByteBuffer)
        int limit = srcBuf.limit();
        ByteBuffer resBuf = encoder.encode(srcBuf);
        assertEqual(srcBuf.position(), limit);
        assertEqual(srcBuf.limit(), limit);
        assertEqual(resBuf, encodedBuf);
        // reset for next test
        srcBuf.rewind();
        // test String encodeToString(byte[])
        String resEncodeStr = encoder.encodeToString(srcArr);
        assertEqual(resEncodeStr, encodedStr);
        // test int decode(byte[], byte[])
        resArr = new byte[srcArr.length];
        len = decoder.decode(encodedArr, resArr);
        assertEqual(len, srcArr.length);
        assertEqual(resArr, srcArr);
        // test byte[] decode(byte[])
        resArr = decoder.decode(encodedArr);
        assertEqual(resArr, srcArr);
        // test ByteBuffer decode(ByteBuffer)
        limit = encodedBuf.limit();
        resBuf = decoder.decode(encodedBuf);
        assertEqual(encodedBuf.position(), limit);
        assertEqual(encodedBuf.limit(), limit);
        assertEqual(resBuf, srcBuf);
        // reset for next test
        encodedBuf.rewind();
        // test byte[] decode(String)
        resArr = decoder.decode(encodedStr);
        assertEqual(resArr, srcArr);
        // test compatible with sun.misc.Base64Encoder
        if (type == Base64Type.MIME) {
            sun.misc.BASE64Encoder miscEncoder = new BASE64Encoder();
            sun.misc.BASE64Decoder miscDecoder = new BASE64Decoder();
            resArr = decoder.decode(miscEncoder.encode(srcArr));
            assertEqual(resArr, srcArr);
            resArr = encoder.encode(miscDecoder.decodeBuffer(encodedStr));
            assertEqual(new String(resArr, DEF_CHARSET), encodedStr);
        }
    }
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder) BASE64Decoder(sun.misc.BASE64Decoder) BASE64Encoder(sun.misc.BASE64Encoder) ByteBuffer(java.nio.ByteBuffer) BASE64Decoder(sun.misc.BASE64Decoder)

Example 9 with BASE64Decoder

use of sun.misc.BASE64Decoder in project jdk8u_jdk by JetBrains.

the class SignatureAlgorithms method generateSSLContext.

private static SSLContext generateSSLContext(String trustedCertStr, String[] keyCertStrs, String[] keySpecStrs) throws Exception {
    // generate certificate from cert string
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    // create a key store
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(null, null);
    // import the trused cert
    Certificate trusedCert = null;
    ByteArrayInputStream is = null;
    if (trustedCertStr != null) {
        is = new ByteArrayInputStream(trustedCertStr.getBytes());
        trusedCert = cf.generateCertificate(is);
        is.close();
        ks.setCertificateEntry("DSA Signer", trusedCert);
    }
    if (keyCertStrs != null && keyCertStrs.length != 0) {
        for (int i = 0; i < keyCertStrs.length; i++) {
            String keyCertStr = keyCertStrs[i];
            String keySpecStr = keySpecStrs[i];
            // generate the private key.
            PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(keySpecStr));
            KeyFactory kf = KeyFactory.getInstance("DSA");
            DSAPrivateKey priKey = (DSAPrivateKey) kf.generatePrivate(priKeySpec);
            // generate certificate chain
            is = new ByteArrayInputStream(keyCertStr.getBytes());
            Certificate keyCert = cf.generateCertificate(is);
            is.close();
            Certificate[] chain = null;
            if (trusedCert != null) {
                chain = new Certificate[2];
                chain[0] = keyCert;
                chain[1] = trusedCert;
            } else {
                chain = new Certificate[1];
                chain[0] = keyCert;
            }
            // import the key entry.
            ks.setKeyEntry("DSA Entry " + i, priKey, passphrase, chain);
        }
    }
    // create SSL context
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
    tmf.init(ks);
    SSLContext ctx = SSLContext.getInstance("TLS");
    if (keyCertStrs != null && keyCertStrs.length != 0) {
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
        kmf.init(ks, passphrase);
        ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        ks = null;
    } else {
        ctx.init(null, tmf.getTrustManagers(), null);
    }
    return ctx;
}
Also used : CertificateFactory(java.security.cert.CertificateFactory) KeyStore(java.security.KeyStore) BASE64Decoder(sun.misc.BASE64Decoder) KeyFactory(java.security.KeyFactory) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 10 with BASE64Decoder

use of sun.misc.BASE64Decoder in project paascloud-master by paascloud.

the class HttpAesUtil method decrypt.

/**
 * 解密
 *
 * @param contentParam 需要加密的内容
 * @param keyParam     加密密码
 * @param md5Key       是否对key进行md5加密
 * @param ivParam      加密向量
 *
 * @return string
 */
public static String decrypt(String contentParam, String keyParam, boolean md5Key, String ivParam) {
    try {
        if (PubUtils.isNull(contentParam, keyParam, md5Key, ivParam)) {
            return "";
        }
        byte[] content = new BASE64Decoder().decodeBuffer(contentParam);
        byte[] key = keyParam.getBytes(CHAR_SET);
        byte[] iv = ivParam.getBytes(CHAR_SET);
        if (md5Key) {
            MessageDigest md = MessageDigest.getInstance("MD5");
            key = md.digest(key);
        }
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        // "算法/模式/补码方式"
        Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding");
        // 使用CBC模式, 需要一个向量iv, 可增加加密算法的强度
        IvParameterSpec ivps = new IvParameterSpec(iv);
        cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivps);
        byte[] bytes = cipher.doFinal(content);
        return new String(bytes, CHAR_SET);
    } catch (Exception ex) {
        log.error("解密密码失败", ex);
        throw new HttpAesException("解密失败");
    }
}
Also used : HttpAesException(com.paascloud.exception.HttpAesException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MessageDigest(java.security.MessageDigest) BASE64Decoder(sun.misc.BASE64Decoder) HttpAesException(com.paascloud.exception.HttpAesException)

Aggregations

BASE64Decoder (sun.misc.BASE64Decoder)10 IOException (java.io.IOException)2 KeyFactory (java.security.KeyFactory)2 KeyStore (java.security.KeyStore)2 Certificate (java.security.cert.Certificate)2 CertificateFactory (java.security.cert.CertificateFactory)2 Cipher (javax.crypto.Cipher)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 JBLabel (com.intellij.ui.components.JBLabel)1 HttpAesException (com.paascloud.exception.HttpAesException)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 ByteBuffer (java.nio.ByteBuffer)1 MessageDigest (java.security.MessageDigest)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1