-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFingerPrint.java
More file actions
61 lines (46 loc) · 1.7 KB
/
FingerPrint.java
File metadata and controls
61 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package fingerprint;
/**
*
* @author Siddharth
*/
import java.io.FileInputStream;
import java.security.MessageDigest;
import javax.swing.*;
import sun.misc.BASE64Encoder;
public class FingerPrint {
/**
* @param args the command line arguments
*/
// TODO code application logic her..
/**
* Builds the finger print of file, crypto hash value
*/
public static void main(String[] args) throws Exception {
// get the file path e.g. c:\Docs\zigzag.txt
String inputText = JOptionPane.showInputDialog("file path to be encrypted ");
// trying to build new message digest which represents and encapsulates
// the Message Java Digest
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
// calculating from the given file running its inside
// while calculating the digest formula
FileInputStream input = new FileInputStream(inputText);
byte[] buffer = new byte[8192];
int length;
while( (length = input.read(buffer)) != -1 ) {
messageDigest.update(buffer, 0, length);
}
byte[] raw = messageDigest.digest();
//printout in 64 base
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(raw);
// and display the results
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
"your file finger print is "
+ new String(base64.toString()));
} // main method end
} // class end