FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Experiments/SHA512.java at master · biblelamp/JavaExercises · GitHub
biblelamp
/
JavaExercises
Public
Notifications
You must be signed in to change notification settings
Fork
130
Star
153
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExercises
/
Experiments
/
SHA512.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (37 loc) · 1.59 KB
Breadcrumbs
JavaExercises
/
Experiments
/
SHA512.java
Copy path
File metadata and controls
49 lines (37 loc) · 1.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Java program to calculate SHA-512 hash value
import
java
.
math
.
BigInteger
;
import
java
.
security
.
MessageDigest
;
import
java
.
security
.
NoSuchAlgorithmException
;
public
class
SHA512
{
public
static
String
encryptThisString
(
String
input
) {
try
{
// getInstance() method is called with algorithm SHA-512
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-512"
);
// digest() method is called
// to calculate message digest of the input string
// returned as array of byte
byte
[]
messageDigest
=
md
.
digest
(
input
.
getBytes
());
// Convert byte array into signum representation
BigInteger
no
=
new
BigInteger
(
1
,
messageDigest
);
// Convert message digest into hex value
String
hashtext
=
no
.
toString
(
16
);
// Add preceding 0s to make it 32 bit
while
(
hashtext
.
length
() <
32
) {
hashtext
=
"0"
+
hashtext
;
}
// return the HashText
return
hashtext
;
}
// For specifying wrong message digest algorithms
catch
(
NoSuchAlgorithmException
e
) {
throw
new
RuntimeException
(
e
);
}
}
public
static
void
main
(
String
args
[])
throws
NoSuchAlgorithmException
{
System
.
out
.
println
(
"HashCode Generated by SHA-512 for:"
);
String
s1
=
"GeeksForGeeks"
;
System
.
out
.
println
(
"
\n
"
+
s1
+
":
\n
"
+
encryptThisString
(
s1
));
String
s2
=
"hello world"
;
System
.
out
.
println
(
"
\n
"
+
s2
+
":
\n
"
+
encryptThisString
(
s2
));
}
}
Back
|
FazBrowse Home
|
New Git URL