java类javax.xml.bind.annotation.adapters.HexBinaryAdapter的实例源码

HexString.java 文件源码 项目:Oscar 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 
 * @param sHexString

 * @return byte[]
 */
public static byte[] toByteArray(String sHexString) {

    //Need to add HexString Check   
    sHexString = sHexString .replaceAll("(\\]|\\)|\\}|\\(|\\[|\\{)", "")
                            .replace(":", "");

    HexBinaryAdapter adapter = new HexBinaryAdapter();       

     if (isModulus(sHexString.replace(" ", "")))
         return adapter.unmarshal(sHexString.replace(" ", ""));
     else
         return new HexString().toByteArray();
}
DigestHelper.java 文件源码 项目:archistar-bft 阅读 17 收藏 0 点赞 0 评论 0
public static synchronized String createResultHash(int sequence, byte[] data) {

        createMd();

        md.update(ByteBuffer.allocate(4).putInt(sequence).array());
        if (data != null) {
            md.update(data);
        }

        /* store the hash */
        return (new HexBinaryAdapter()).marshal(md.digest());
    }
HDFSFiler.java 文件源码 项目:dm-hdfs-storage 阅读 20 收藏 0 点赞 0 评论 0
@Override
public String createChecksum(String fileName, MessageDigest md) throws IOException {        

    byte[] digest = createChecksum(getInputStream(fileName), md);
    String hex = (new HexBinaryAdapter()).marshal(digest).toLowerCase();
    return hex;
}
FSFiler.java 文件源码 项目:dm-hdfs-storage 阅读 20 收藏 0 点赞 0 评论 0
@Override
public String createChecksum(String fileName, MessageDigest md) throws IOException {

    byte[] digest = createChecksum(getInputStream(fileName), md);
    String hex = (new HexBinaryAdapter()).marshal(digest).toLowerCase();
    return hex;
}
MultipleDigestInputStream.java 文件源码 项目:dhus-core 阅读 18 收藏 0 点赞 0 评论 0
public String getMessageDigestAsHexadecimalString (String algorithm)
{
   return (new HexBinaryAdapter()).marshal (
      getMessageDigest (algorithm).digest ());
}
MultipleDigestOutputStream.java 文件源码 项目:dhus-core 阅读 21 收藏 0 点赞 0 评论 0
public String getMessageDigestAsHexadecimalString (String algorithm)
{
   return (new HexBinaryAdapter()).marshal (
      getMessageDigest (algorithm).digest ());
}
HashUtils.java 文件源码 项目:EMC 阅读 27 收藏 0 点赞 0 评论 0
public static String getSHA(String string) throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-512");
    sha1.update(string.getBytes());
    return new HexBinaryAdapter().marshal(sha1.digest());
}
Controller.java 文件源码 项目:MakeSourceList4j 阅读 26 收藏 0 点赞 0 评论 0
public static byte[] hexToBytes(String hexString) {
    HexBinaryAdapter adapter = new HexBinaryAdapter();
    byte[] bytes = adapter.unmarshal(hexString);
    return bytes;
}
VaultODVExporter.java 文件源码 项目:BachelorPraktikum 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Writes the data to a CSV file and generates a signature hash.
 * Then it puts both of this into a ZIP archive file.
 *
 * @param csvEntries The {@link ExportEntry} to be exported.
 * @throws IOException Thrown if the SHA-512 hash algorithm is missing.
 */
@Override
protected void writeToFile(final List<ExportEntry> csvEntries) throws IOException {
    // Setup compression stuff
    FileOutputStream fileOutputStream = getFileOutputStream();
    final int zipCompressionLevel = 9;

    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    zipOutputStream.setMethod(ZipOutputStream.DEFLATED);
    zipOutputStream.setLevel(zipCompressionLevel);

    // Setup signature
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-512");
    } catch (NoSuchAlgorithmException exception) {
        LOG.log(Level.SEVERE, "Missing hash algorithm for signature. No file exported!", exception);
        throw new IOException("Missing hash algorithm for signature.");
    }
    DigestOutputStream digestOutputStream = new DigestOutputStream(zipOutputStream, digest);

    // write data
    zipOutputStream.putNextEntry(new ZipEntry(DATA_ZIP_ENTRY));
    CsvWriter cwriter = new CsvWriter(digestOutputStream, VaultCsvEntry.CSV_DELIMITER,
            Charset.forName("UTF-8"));

    cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
    for (ExportEntry item : csvEntries) {
        cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
    }
    cwriter.flush();

    // add signature file
    zipOutputStream.putNextEntry(new ZipEntry(SIGNATURE_ZIP_ENTRY));
    String sigString = (new HexBinaryAdapter()).marshal(digest.digest());
    zipOutputStream.write(sigString.getBytes("UTF-8"), 0, sigString.getBytes("UTF-8").length);

    // Closing the streams
    cwriter.close();
    digestOutputStream.close();
    zipOutputStream.close();
    fileOutputStream.close();
}
Btcd.java 文件源码 项目:Shufflepuff 阅读 21 收藏 0 点赞 0 评论 0
/**
 * This method takes in a transaction hash and returns a bitcoinj transaction object.
 */
synchronized org.bitcoinj.core.Transaction getTransaction(String transactionHash) throws IOException {

    org.bitcoinj.core.Transaction tx = null;
    String requestBody = "{\"jsonrpc\":\"2.0\",\"id\":\"null\",\"method\":\"getrawtransaction\", \"params\":[\"" + transactionHash + "\"]}";

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setRequestProperty("Accept", "application/json");
    Base64 b = new Base64();
    String authString = rpcuser + ":" + rpcpass;
    String encoding = b.encodeAsString(authString.getBytes());
    connection.setRequestProperty("Authorization", "Basic " + encoding);
    connection.setRequestProperty("Content-Length", Integer.toString(requestBody.getBytes().length));
    connection.setDoInput(true);
    OutputStream out = connection.getOutputStream();
    out.write(requestBody.getBytes());

    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String line;
        StringBuffer response = new StringBuffer();
        while ((line = rd.readLine()) != null) {
            response.append(line);
            response.append('\r');
        }
        rd.close();

        JSONObject json = new JSONObject(response.toString());
        String hexTx = (String) json.get("result");
        HexBinaryAdapter adapter = new HexBinaryAdapter();
        byte[] bytearray = adapter.unmarshal(hexTx);
        Context context = Context.getOrCreate(netParams);
        tx = new org.bitcoinj.core.Transaction(netParams, bytearray);

    }

    out.flush();
    out.close();

    return tx;

}


问题


面经


文章

微信
公众号

扫码关注公众号