File tree Expand file tree Collapse file tree 3 files changed +74
-1
lines changed
services-api/src/main/java/io/scalecube/services Expand file tree Collapse file tree 3 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 1+ package io .scalecube .services ;
2+
3+ public final class HexUtil {
4+
5+ private HexUtil () {
6+ // Do not instantiate
7+ }
8+
9+ /**
10+ * Converts bytes array to hex string.
11+ *
12+ * @param bytes bytes array
13+ * @return hex string
14+ */
15+ public static String toHex (byte [] bytes ) {
16+ StringBuilder sb = new StringBuilder ();
17+ for (byte b : bytes ) {
18+ sb .append (String .format ("%02x" , b ));
19+ }
20+ return sb .toString ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package io .scalecube .services ;
2+
3+ import java .util .Map ;
4+ import java .util .Map .Entry ;
5+ import java .util .UUID ;
6+ import java .util .stream .Collectors ;
7+
8+ public final class MaskUtil {
9+
10+ private MaskUtil () {
11+ // Do not instantiate
12+ }
13+
14+ /**
15+ * Mask sensitive data by replacing part of string with an asterisk symbol.
16+ *
17+ * @param data sensitive data to be masked
18+ * @return masked data
19+ */
20+ public static String mask (String data ) {
21+ if (data == null || data .length () < 5 ) {
22+ return "*****" ;
23+ }
24+ return data .replace (data .substring (2 , data .length () - 2 ), "***" );
25+ }
26+
27+ /**
28+ * Mask sensitive data by replacing part of string with an asterisk symbol.
29+ *
30+ * @param data sensitive data to be masked
31+ * @return masked data
32+ */
33+ public static String mask (UUID data ) {
34+ return data != null ? mask (data .toString ()) : null ;
35+ }
36+
37+ /**
38+ * Mask sensitive data by replacing part of string with an asterisk symbol.
39+ *
40+ * @param map map with sensitive data to be masked
41+ * @return string representation
42+ */
43+ public static String mask (Map <String , String > map ) {
44+ if (map == null || map .isEmpty ()) {
45+ return String .valueOf (map );
46+ }
47+ return map .entrySet ().stream ()
48+ .collect (Collectors .toMap (Entry ::getKey , entry -> mask (entry .getValue ())))
49+ .toString ();
50+ }
51+ }
Original file line number Diff line number Diff line change 3232import reactor .core .scheduler .Scheduler ;
3333import reactor .core .scheduler .Schedulers ;
3434
35- public class Reflect {
35+ public final class Reflect {
3636
3737 private Reflect () {
3838 // Do not instantiate
You can’t perform that action at this time.
0 commit comments