KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > softabar > sha4j > Sha256


1 /*
2  * Copyright (C) 2006 Softabar
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, * Inc., * 59 Temple Place, * Suite 330,
17  * Boston, MA 02111-1307 USA
18 */

19 package com.softabar.sha4j;
20
21 import java.io.File JavaDoc;
22
23 /**
24  * Usage: java com.softabar.sha4j.Sha256 <text> or Sha256 -f<filename>. <br/>
25  * Calculates SHA-256 from text or file.
26  *
27  * <pre>
28  * Copyright (C) 2006 Softabar
29  *
30  * This program is free software; you can redistribute it and/or modify it
31  * under the terms of the GNU General Public License as published by the
32  * Free Software Foundation; either version 2 of the License, or
33  * (at your option) any later version.
34  *
35  * This program is distributed in the hope that it will be useful, but
36  * WITHOUT ANY WARRANTY; without even the implied warranty of
37  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38  * GNU General Public License for more details.
39  *
40  * You should have received a copy of the GNU General Public License
41  * along with this program; if not, write to the
42  * Free Software Foundation, * Inc., * 59 Temple Place, * Suite 330,
43  * Boston, MA 02111-1307 USA
44  * </pre>
45  *
46  * @version 1.0
47 */

48 public class Sha256
49 {
50   public static void main(String JavaDoc[] args)
51   {
52     try
53     {
54       String JavaDoc text=args[0];
55       if(text==null)
56       {
57         System.out.println("Usage: Sha256 <text> or Sha256 -f<filename>");
58         return;
59       }
60       if(text.startsWith("-f"))
61       {
62         System.out.println(ShaUtil.toSha256String(new File JavaDoc(text.substring(2))));
63         
64       }
65       else
66       {
67         System.out.println(ShaUtil.toSha256String(text));
68       }
69     }
70     catch(Exception JavaDoc e)
71     {
72       System.out.println(e.toString());
73       System.out.println("Usage: Sha256 <text> or Sha256 -f<filename>");
74     }
75
76   }
77
78 }
79
Popular Tags