-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoUtil.java
More file actions
37 lines (33 loc) · 980 Bytes
/
CryptoUtil.java
File metadata and controls
37 lines (33 loc) · 980 Bytes
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package week04;
/**
*
* @author levan
*/
public class CryptoUtil {
public static String toHexString (byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b :bytes) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append (hex);
}
return hexString.toString();
}
public static final void byte2hex(byte b, StringBuffer buf) {
char[] hexChars = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};
int high = ((b & 0xf0) >> 4);
int low = (b & 0x0f);
buf.append (hexChars [high]);
buf.append (hexChars [low]);
}
}