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;
}
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);
}
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("解密失败");
}
}
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]);
}
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);
}
}
Aggregations