Example usage for org.apache.poi.util HexDump toHex

List of usage examples for org.apache.poi.util HexDump toHex

Introduction

In this page you can find the example usage for org.apache.poi.util HexDump toHex.

Prototype

public static String toHex(String value) 

Source Link

Document

Converts the string to a string of hex values by using String.getBytes(LocaleUtil.CHARSET_1252) to convert the string to a byte-array.

Usage

From source file:org.apache.xml.security.utils.SignerOutputStream.java

License:Apache License

/** @inheritDoc */
public void write(byte[] arg0, int arg1, int arg2) {
    if (log.isDebugEnabled()) {
        log.debug("Canonicalized SignedInfo:");
        StringBuilder sb = new StringBuilder(arg2);
        for (int i = arg1; i < (arg1 + arg2); i++) {
            sb.append((char) arg0[i]);
        }/* w ww  . j av a  2s  .  c  om*/
        log.debug(sb.toString());
    }
    try {

        System.err.println("SignerOutputStream.write():" + new String(arg0, arg1, arg2));

        try {
            MessageDigest hash = MessageDigest.getInstance("SHA-256", "BC");
            hash.reset();
            byte[] toHash = new byte[arg2];
            System.arraycopy(arg0, arg1, toHash, 0, arg2);
            // toHash =
            // Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS).canonicalize(toHash);
            EbicsUtil.saveToFile(toHash, new File("toHash.bin"));
            ByteArrayOutputStream o = new ByteArrayOutputStream();
            for (int i = 0; i < toHash.length; i++) {
                byte b = toHash[i];
                // if (b != 26 && b != 10 && b != 13) {
                o.write(b);
                // }
            }
            o.close();
            // toHash = o.toByteArray();
            EbicsUtil.saveToFile(toHash, new File("toHash.bin"));
            byte[] r = hash.digest(toHash);
            // r = hash.digest(toHash);
            System.err.println("== toHash");
            System.err.println(new String(toHash));
            System.err.println(HexDump.toHex(toHash));
            System.err.println("== r");
            System.err.println(HexDump.toHex(r));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        sa.update(arg0, arg1, arg2);
    } catch (XMLSignatureException e) {
        throw new RuntimeException("" + e);
    }
}