File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/com/gitblit/utils
test/java/com/gitblit/tests Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -336,6 +336,28 @@ public static String getSHA1(byte[] bytes)
336
336
{
337
337
return getDigest (bytes , "SHA-1" );
338
338
}
339
+
340
+
341
+ /**
342
+ * Calculates the SHA256 of the string.
343
+ *
344
+ * @param text
345
+ * @return sha256 of the string
346
+ */
347
+ public static String getSHA256 (String text )
348
+ {
349
+ return getDigest (text , "SHA-256" );
350
+ }
351
+
352
+ /**
353
+ * Calculates the SHA256 of the byte array.
354
+ *
355
+ * @param bytes
356
+ * @return sha256 of the byte array
357
+ */
358
+ public static String getSHA256 (byte [] bytes )
359
+ {
360
+ return getDigest (bytes , "SHA-256" );
339
361
}
340
362
341
363
/**
Original file line number Diff line number Diff line change @@ -133,6 +133,12 @@ public void testSHA1() throws Exception {
133
133
StringUtils .getSHA1 ("blob 16\000 what is up, doc?" ));
134
134
}
135
135
136
+ @ Test
137
+ public void testSHA256 () throws Exception {
138
+ assertEquals ("badf72532e259f2b67a40475486c7e71bf48bc71d7b0d43d8e99acfb3ac24e1b" ,
139
+ StringUtils .
getSHA256 (
"[email protected] " ));
140
+ }
141
+
136
142
@ Test
137
143
public void testMD5 () throws Exception {
138
144
assertEquals ("77fb8d95331f0d557472f6776d3aedf6" ,
You can’t perform that action at this time.
0 commit comments