Search in sources :

Example 36 with BASE64Decoder

use of sun.misc.BASE64Decoder in project j2objc by google.

the class X509CertImpl method readRFC1421Cert.

/**
 * read input stream as HEX-encoded DER-encoded bytes
 *
 * @param in InputStream to read
 * @returns DerValue corresponding to decoded HEX-encoded bytes
 * @throws IOException if stream can not be interpreted as RFC1421
 *                     encoded bytes
 */
private DerValue readRFC1421Cert(InputStream in) throws IOException {
    DerValue der = null;
    String line = null;
    BufferedReader certBufferedReader = new BufferedReader(new InputStreamReader(in, "ASCII"));
    try {
        line = certBufferedReader.readLine();
    } catch (IOException ioe1) {
        throw new IOException("Unable to read InputStream: " + ioe1.getMessage());
    }
    if (line.equals(X509Factory.BEGIN_CERT)) {
        /* stream appears to be hex-encoded bytes */
        BASE64Decoder decoder = new BASE64Decoder();
        ByteArrayOutputStream decstream = new ByteArrayOutputStream();
        try {
            while ((line = certBufferedReader.readLine()) != null) {
                if (line.equals(X509Factory.END_CERT)) {
                    der = new DerValue(decstream.toByteArray());
                    break;
                } else {
                    decstream.write(decoder.decodeBuffer(line));
                }
            }
        } catch (IOException ioe2) {
            throw new IOException("Unable to read InputStream: " + ioe2.getMessage());
        }
    } else {
        throw new IOException("InputStream is not RFC1421 hex-encoded " + "DER bytes");
    }
    return der;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BASE64Decoder(sun.misc.BASE64Decoder)

Example 37 with BASE64Decoder

use of sun.misc.BASE64Decoder in project j2objc by google.

the class SignatureFileVerifier method processImpl.

private void processImpl(Hashtable<String, CodeSigner[]> signers, List manifestDigests) throws IOException, SignatureException, NoSuchAlgorithmException, JarException, CertificateException {
    Manifest sf = new Manifest();
    sf.read(new ByteArrayInputStream(sfBytes));
    String version = sf.getMainAttributes().getValue(Attributes.Name.SIGNATURE_VERSION);
    if ((version == null) || !(version.equalsIgnoreCase("1.0"))) {
        // for now we just ignore this signature file
        return;
    }
    SignerInfo[] infos = block.verify(sfBytes);
    if (infos == null) {
        throw new SecurityException("cannot verify signature block file " + name);
    }
    BASE64Decoder decoder = new BASE64Decoder();
    CodeSigner[] newSigners = getSigners(infos, block);
    // make sure we have something to do all this work for...
    if (newSigners == null)
        return;
    Iterator<Map.Entry<String, Attributes>> entries = sf.getEntries().entrySet().iterator();
    // see if we can verify the whole manifest first
    boolean manifestSigned = verifyManifestHash(sf, md, decoder, manifestDigests);
    // verify manifest main attributes
    if (!manifestSigned && !verifyManifestMainAttrs(sf, md, decoder)) {
        throw new SecurityException("Invalid signature file digest for Manifest main attributes");
    }
    // go through each section in the signature file
    while (entries.hasNext()) {
        Map.Entry<String, Attributes> e = entries.next();
        String name = e.getKey();
        if (manifestSigned || (verifySection(e.getValue(), name, md, decoder))) {
            if (name.startsWith("./"))
                name = name.substring(2);
            if (name.startsWith("/"))
                name = name.substring(1);
            updateSigners(newSigners, signers, name);
            if (debug != null) {
                debug.println("processSignature signed name = " + name);
            }
        } else if (debug != null) {
            debug.println("processSignature unsigned name = " + name);
        }
    }
    // MANIFEST.MF is always regarded as signed
    updateSigners(newSigners, signers, JarFile.MANIFEST_NAME);
}
Also used : BASE64Decoder(sun.misc.BASE64Decoder)

Example 38 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)

Example 39 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 40 with BASE64Decoder

use of sun.misc.BASE64Decoder in project pmph by BCSquad.

the class BookSyncController method decrypt.

/**
 * 根据密钥对指定的密文cipherText进行解密.
 *
 * @param cipherText 密文
 * @return 解密后的明文.
 */
public static final String decrypt(String cipherText) {
    Key secretKey = getKey("medu");
    try {
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] c = decoder.decodeBuffer(cipherText);
        byte[] result = cipher.doFinal(c);
        String plainText = new String(result, "UTF-8");
        return plainText;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Cipher(javax.crypto.Cipher) BASE64Decoder(sun.misc.BASE64Decoder) Key(java.security.Key) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException)

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