Example usage for org.apache.commons.codec.binary Hex encodeHexString

List of usage examples for org.apache.commons.codec.binary Hex encodeHexString

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex encodeHexString.

Prototype

public static String encodeHexString(byte[] data) 

Source Link

Document

Converts an array of bytes into a String representing the hexadecimal values of each byte in order.

Usage

From source file:md5.demo.MD5Demo.java

public static void main(String[] args) {
    String input = "123456";
    try {/*  ww  w  . j  a v  a2 s .com*/
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        byte[] output = messageDigest.digest(input.getBytes());
        String outString = Hex.encodeHexString(output);
        System.out.println(outString);

    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    }

}

From source file:com.java.demo.DesDemo.java

public static void main(String[] args) {
    //des(data crpt)
    Init();/* w  ww.j  av  a 2s . c om*/
    byte[] strBytes = Encrypt("abc");
    System.out.println(Hex.encodeHexString(strBytes));
    byte[] str = Decrypt(strBytes);
    System.out.println(new String(str));
}

From source file:com.java.demo.RsaDemo.java

public static void main(String[] args) {
    Init();//from  w  w  w  .  j ava  2s .  com
    String str = "123";
    byte[] result = Encrypt(str);
    System.out.println(Hex.encodeHexString(result));
    boolean verifyRet = Verify(str, result);
    System.out.println("com.Java.Demo.RsaDemo.main()" + verifyRet);
}

From source file:com.mfizz.ruby.demo.MarshalMain.java

static public void main(String[] args) throws Exception {
    // use following code in ruby to test decoding stuff
    // Marshal.load(["040830"].pack('H*')).inspect()

    // object w/ no vars
    RubyObject obj = new RubyObject(new RubySymbol("Object"));
    // add some vars
    obj.put(new RubySymbol("@test"), new RubyString("test".getBytes()));

    logger.info("obj to marshal: {}", Ruby.toString(obj));

    byte[] bytes = Marshal.dump(obj);
    logger.info("marshal dump: {}", Hex.encodeHexString(bytes));

    // try to load it back up
    RubyType obj2 = Marshal.load(bytes);
    logger.info("marshal load: {}", Ruby.toString(obj2));
}

From source file:com.lightboxtechnologies.nsrl.OCSVTest.java

public static void main(String[] args) throws IOException {
    final String mfg_filename = args[0];
    final String os_filename = args[1];
    final String prod_filename = args[2];
    final String hash_filename = args[3];

    final LineTokenizer tok = new OpenCSVLineTokenizer();
    final RecordLoader loader = new RecordLoader();

    final ErrorConsumer err = new ErrorConsumer() {
        public void consume(BadDataException e, long linenum) {
            System.err.println("malformed record, line " + linenum);
            e.printStackTrace();//from   w  w w .j a  v a 2s .c  o  m
        }
    };

    // read manufacturer, OS, product data
    final Map<String, MfgData> mfg = new HashMap<String, MfgData>();
    final Map<String, OSData> os = new HashMap<String, OSData>();
    final Map<Integer, List<ProdData>> prod = new HashMap<Integer, List<ProdData>>();

    SmallTableLoader.load(mfg_filename, mfg, os_filename, os, prod_filename, prod, tok, err);

    // read hash data
    final RecordConsumer<HashData> hcon = new RecordConsumer<HashData>() {
        public void consume(HashData hd) {
            /*
                    System.out.print(hd);
                    
                    for (ProdData pd : prod.get(hd.prod_code)) {
                      System.out.print(pd);
                      final MfgData pmd = mfg.get(pd.mfg_code);
                      System.out.print(pmd);
                    }
                    
                    final OSData osd = os.get(hd.os_code);
                    System.out.print(osd);
                    
                    final MfgData osmd = mfg.get(osd.mfg_code);
                    System.out.print(osmd);
                    
                    System.out.println("");
            */

            /*
                    final Hex hex = new Hex();
                    
                    String sha1 = null;
                    String md5 = null;
                    String crc32 = null;
                    
                    try {
                      sha1 = (String) hex.encode((Object) hd.sha1);
                      md5 = (String) hex.encode((Object) hd.md5);
                      crc32 = (String) hex.encode((Object) hd.crc32);
                    }
                    catch (EncoderException e) {
                      throw new RuntimeException(e);
                    }
            */

            final ObjectMapper mapper = new ObjectMapper();

            final String sha1 = Hex.encodeHexString(hd.sha1);
            final String md5 = Hex.encodeHexString(hd.md5);
            final String crc32 = Hex.encodeHexString(hd.crc32);

            final Map<String, Object> hd_m = new HashMap<String, Object>();

            hd_m.put("sha1", sha1);
            hd_m.put("md5", md5);
            hd_m.put("crc32", crc32);
            hd_m.put("name", hd.name);
            hd_m.put("size", hd.size);
            hd_m.put("special_code", hd.special_code);

            final OSData osd = os.get(hd.os_code);
            final MfgData osmfgd = mfg.get(osd.mfg_code);

            final Map<String, Object> os_m = new HashMap<String, Object>();
            os_m.put("name", osd.name);
            os_m.put("version", osd.version);
            os_m.put("manufacturer", osmfgd.name);
            hd_m.put("os", os_m);

            final List<Map<String, Object>> pl_l = new ArrayList<Map<String, Object>>();
            for (ProdData pd : prod.get(hd.prod_code)) {

                if (!osd.code.equals(pd.os_code)) {
                    // os code mismatch
                    /*
                                System.err.println(
                                  "Hash record OS code == " + osd.code + " != " + pd.os_code + " == product record OS code"
                                );
                    */
                    continue;
                }

                final Map<String, Object> prod_m = new HashMap<String, Object>();

                prod_m.put("name", pd.name);
                prod_m.put("version", pd.version);
                prod_m.put("language", pd.language);
                prod_m.put("app_type", pd.app_type);
                prod_m.put("os_code", pd.os_code);

                final MfgData md = mfg.get(pd.mfg_code);
                prod_m.put("manufacturer", md.name);

                pl_l.add(prod_m);
            }

            if (pl_l.size() > 1) {
                System.err.println(hd.prod_code);
            }

            hd_m.put("products", pl_l);

            try {
                mapper.writeValue(System.out, hd_m);
            } catch (IOException e) {
                // should be impossible
                throw new IllegalStateException(e);
            }
        }
    };

    final RecordProcessor<HashData> hproc = new HashRecordProcessor();
    final LineHandler hlh = new DefaultLineHandler<HashData>(tok, hproc, hcon, err);

    InputStream zin = null;
    try {
        //      zin = new GZIPInputStream(new FileInputStream(hash_filename));
        zin = new FileInputStream(hash_filename);
        loader.load(zin, hlh);
        zin.close();
    } finally {
        IOUtils.closeQuietly(zin);
    }

    System.out.println();

    /*
        for (Map.Entry<String,String> e : mfg.entrySet()) {
          System.out.println(e.getKey() + " = " + e.getValue());
        }
            
        for (Map.Entry<String,OSData> e : os.entrySet()) {
          System.out.println(e.getKey() + " = " + e.getValue());
        }
            
        for (Map.Entry<Integer,List<ProdData>> e : prod.entrySet()) {
          System.out.println(e.getKey() + " = " + e.getValue());
        }
    */
}

From source file:com.lhings.java.utils.ByteMan.java

public static void main(String[] args) throws DecoderException {
    byte[] a = { (byte) 0x12, (byte) 0xfa, (byte) 0xa4, (byte) 0xc5 };
    for (byte b : a)
        System.out.print(b + ", ");
    System.out.println();/*www . j a  v a2 s.c o  m*/
    String str = Hex.encodeHexString(a);
    System.out.println(str);
    byte[] c = Hex.decodeHex(str.toCharArray());
    for (byte b : c)
        System.out.print(b + ", ");
    System.out.println();
}

From source file:com.playonlinux.utils.cab.Cabfile.java

public static void main(String[] args) throws CabException, IOException {
    File tahoma32 = new File("/Users/tinou/Downloads/arial32.exe");
    Cabfile cabfile = new Cabfile(tahoma32);
    int offset = cabfile.findCabOffset();
    System.out.println(offset);/*from  www. j  av a2 s.c o m*/
    CFHeader header = cabfile.getHeader();

    List<CFFolder> cfFolders = new ArrayList<>();
    for (int i = 0; i < header.getNumberOfFolders(); i++) {
        CFFolder cfFolder = cabfile.getFolder();
        cfFolders.add(cfFolder);
        System.out.println(cfFolder);
    }

    cabfile.jumpTo(header.coffFiles[0]);

    List<CFFile> cfiles = new ArrayList<>();
    for (int i = 0; i < header.getNumberOfFiles(); i++) {
        CFFile cfile = cabfile.getFile();
        cfiles.add(cfile);
        System.out.println(cfile);
    }

    CFData cfData = cabfile.getData(CompressionType.NONE);
    System.out.println(cfData);
    System.out.println(Hex.encodeHexString(cfData.ab));

    CFData cfData2 = cabfile.getData(CompressionType.NONE);
    System.out.println(cfData2);
    System.out.println(Hex.encodeHexString(cfData2.ab));

    /*
    for(CFFile cfFile: cfiles) {
    if("fontinst.inf".equals(cfFile.getFilename())) {
        CFFolder cfFolder = cfFolders.get((int) cfFile.getFolderIndex());
            
            
        long dataIndex = cfFolder.getOffsetStartData() + cfFile.getOffsetStartDataInsideFolder();
            
        System.out.print("Index: ");
        System.out.println(dataIndex);
            
        cabfile.jumpTo(dataIndex);
            
            
        CFData cfData = cabfile.getData();
            
            
        cfFolder.dump();
        System.out.println(cfFile);
        System.out.println(cfData);
            
        File test = new File("/tmp/test");
        FileOutputStream stream = new FileOutputStream(test);
            
        stream.write(cfData.ab);
        System.out.println(Arrays.toString(cfData.ab));
    }
    } */
}

From source file:com.bjwg.back.util.EncodeUtils.java

public static String encodeHex(byte[] input) {
    return Hex.encodeHexString(input);
}

From source file:cn.newtouch.util.utils.encode.EncodeUtils.java

/**
 * Hex?.
 */
public static String hexEncode(byte[] input) {
    return Hex.encodeHexString(input);
}

From source file:com.apabi.qrcode.utils.EncodeUtils.java

/**
 * Hex?.
 */
public static String hexEncode(final byte[] input) {
    return Hex.encodeHexString(input);
}