List of usage examples for org.apache.commons.compress.utils Charsets ISO_8859_1
Charset ISO_8859_1
To view the source code for org.apache.commons.compress.utils Charsets ISO_8859_1.
Click Source Link
From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1StringType.java
/** * Extracts String object from BER input stream. *///from www . ja v a2 s .c om public Object getDecodedObject(BerInputStream in) throws IOException { /* To ensure we get the correct encoding on non-ASCII platforms, specify that we wish to convert from ASCII to the default platform encoding */ return new String(in.buffer, in.contentOffset, in.length, Charsets.ISO_8859_1); }
From source file:android.framework.util.jar.JarVerifier.java
/** * Invoked for each new JAR entry read operation from the input * stream. This method constructs and returns a new {@link VerifierEntry} * which contains the certificates used to sign the entry and its hash value * as specified in the JAR MANIFEST format. * * @param name/* w ww .java2 s . c o m*/ * the name of an entry in a JAR file which is <b>not</b> in the * {@code META-INF} directory. * @return a new instance of {@link VerifierEntry} which can be used by * callers as an {@link OutputStream}. */ VerifierEntry initEntry(String name) { // If no manifest is present by the time an entry is found, // verification cannot occur. If no signature files have // been found, do not verify. if (man == null || signatures.size() == 0) { return null; } Attributes attributes = man.getAttributes(name); // entry has no digest if (attributes == null) { return null; } ArrayList<Certificate> certs = new ArrayList<Certificate>(); Iterator<Map.Entry<String, HashMap<String, Attributes>>> it = signatures.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, HashMap<String, Attributes>> entry = it.next(); HashMap<String, Attributes> hm = entry.getValue(); if (hm.get(name) != null) { // Found an entry for entry name in .SF file String signatureFile = entry.getKey(); certs.addAll(getSignerCertificates(signatureFile, certificates)); } } // entry is not signed if (certs.isEmpty()) { return null; } Certificate[] certificatesArray = certs.toArray(new Certificate[certs.size()]); String algorithms = attributes.getValue("Digest-Algorithms"); if (algorithms == null) { algorithms = "SHA SHA1"; } StringTokenizer tokens = new StringTokenizer(algorithms); while (tokens.hasMoreTokens()) { String algorithm = tokens.nextToken(); String hash = attributes.getValue(algorithm + "-Digest"); if (hash == null) { continue; } byte[] hashBytes = hash.getBytes(Charsets.ISO_8859_1); try { return new VerifierEntry(name, MessageDigest.getInstance(algorithm), hashBytes, certificatesArray); } catch (NoSuchAlgorithmException e) { // ignored } } return null; }
From source file:android.framework.util.jar.JarVerifier.java
private boolean verify(Attributes attributes, String entry, byte[] data, int start, int end, boolean ignoreSecondEndline, boolean ignorable) { String algorithms = attributes.getValue("Digest-Algorithms"); if (algorithms == null) { algorithms = "SHA SHA1"; }//from w w w.ja v a2 s.co m StringTokenizer tokens = new StringTokenizer(algorithms); while (tokens.hasMoreTokens()) { String algorithm = tokens.nextToken(); String hash = attributes.getValue(algorithm + entry); if (hash == null) { continue; } MessageDigest md; try { md = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { continue; } if (ignoreSecondEndline && data[end - 1] == '\n' && data[end - 2] == '\n') { md.update(data, start, end - 1 - start); } else { md.update(data, start, end - start); } byte[] b = md.digest(); byte[] hashBytes = hash.getBytes(Charsets.ISO_8859_1); return MessageDigest.isEqual(b, Base64.decode(hashBytes, Base64.DEFAULT)); } return ignorable; }