Topic Text   Topic Comments (2)   Topic Properties   Topic Information piluadudhf@sjd...
Topic title: Test Tuesday August 25, 2009 21:21:17

Download topic text | View in variable-width font | Tab width set to 8 (change to 4)

Files in topic:  
[Jump to] Aufgabe2b.java   {+47,-0}

[Add General Comment] to topic.

File Aufgabe2b.java (Revision 1.0) [Add File Comment] [Top]
 
1 package cn7.javasec.blatt8;
2
3 import java.io.BufferedInputStream;
4 import java.io.ByteArrayInputStream;
5 import java.io.FileInputStream;
6 import java.security.DigestInputStream;
7 import java.security.MessageDigest;
8
9 public class Aufgabe2b {
10
11 /**
12 * @param args
13 */
14 public static void main(String[] args) {
15 String alg = "SHA-512";
16 //alg = "MD5";
17
18 try {
19 MessageDigest md = MessageDigest.getInstance(alg);
20
21 DigestInputStream dis = new DigestInputStream(new FileInputStream("digest.file"), md);
22
23 while ((dis.read()) != -1);
24 dis.close();
25
26 // out
27 byte[] out = md.digest();
28 BufferedInputStream br = new BufferedInputStream(new ByteArrayInputStream(out));
29 int k = 0;
30 String output = "";
31 while ((k = br.read()) != -1) {
32 k = k & 0xFF;
33 if (k < 16)
34 output += "0";
35 output += Integer.toString(k, 16).toUpperCase() + " ";
36 }
37 System.out.println("OUT:\n" +output);
38
39
40 System.out.println();
41 } catch (Exception e) {
42 e.printStackTrace();
43 }
44
45 }
46
47 }
 
  
Legend:
Removed 
Changed
 Added

[Add General Comment] to topic.