/* ComputeID.java * * This file is part of Gzz. * * Gzz is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Gzz is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Gzz; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Rauli Ruohonen */ package gzz.mediaserver; import java.security.*; import java.io.*; import java.util.*; import gzz.util.*; public class ComputeID { public static void main(String argv[]) throws Exception { MessageDigest d = MessageDigest.getInstance("SHA"); if (argv.length != 1) { System.err.println("Usage: ComputeID "); System.err.println("Block data is read from stdin."); return; } byte[] id = HexUtil.hexToByteArr(argv[0]); if(id[0] != 0x00) throw new Error("ID format version not supported"); ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; while(true) { int r = System.in.read(buf); if(r == -1) break; os.write(buf, 0, r); } byte[] data = os.toByteArray(); d.reset(); int l = id.length; d.update((byte)((l >>> 24) & 0xff)); d.update((byte)((l >>> 16) & 0xff)); d.update((byte)((l >>> 8) & 0xff)); d.update((byte)(l & 0xff)); d.update(id); d.update(data); byte[] hash = d.digest(); String s = HexUtil.byteArrToHex(id)+HexUtil.byteArrToHex(hash); System.out.println(s); return; } }