@@ -650,11 +650,53 @@ public static String getAppSignatureSHA1() {
650
650
* @return the application's signature for SHA1 value
651
651
*/
652
652
public static String getAppSignatureSHA1 (final String packageName ) {
653
+ return getAppSignatureHash (packageName , "SHA1" );
654
+ }
655
+
656
+ /**
657
+ * Return the application's signature for SHA256 value.
658
+ *
659
+ * @return the application's signature for SHA256 value
660
+ */
661
+ public static String getAppSignatureSHA256 () {
662
+ return getAppSignatureSHA256 (Utils .getApp ().getPackageName ());
663
+ }
664
+
665
+ /**
666
+ * Return the application's signature for SHA256 value.
667
+ *
668
+ * @param packageName The name of the package.
669
+ * @return the application's signature for SHA256 value
670
+ */
671
+ public static String getAppSignatureSHA256 (final String packageName ) {
672
+ return getAppSignatureHash (packageName , "SHA256" );
673
+ }
674
+
675
+ /**
676
+ * Return the application's signature for MD5 value.
677
+ *
678
+ * @return the application's signature for MD5 value
679
+ */
680
+ public static String getAppSignatureMD5 () {
681
+ return getAppSignatureMD5 (Utils .getApp ().getPackageName ());
682
+ }
683
+
684
+ /**
685
+ * Return the application's signature for MD5 value.
686
+ *
687
+ * @param packageName The name of the package.
688
+ * @return the application's signature for MD5 value
689
+ */
690
+ public static String getAppSignatureMD5 (final String packageName ) {
691
+ return getAppSignatureHash (packageName , "MD5" );
692
+ }
693
+
694
+ private static String getAppSignatureHash (final String packageName , final String algorithm ) {
653
695
if (isSpace (packageName )) return "" ;
654
696
Signature [] signature = getAppSignature (packageName );
655
697
if (signature == null || signature .length <= 0 ) return "" ;
656
- return encryptSHA1ToString ( signature [0 ].toByteArray ()).
657
- replaceAll ("(?<=[0-9A-F]{2})[0-9A-F]{2}" , ":$0" );
698
+ return bytes2HexString ( hashTemplate ( signature [0 ].toByteArray (), algorithm ))
699
+ . replaceAll ("(?<=[0-9A-F]{2})[0-9A-F]{2}" , ":$0" );
658
700
}
659
701
660
702
/**
@@ -860,14 +902,10 @@ private static boolean isDeviceRooted() {
860
902
private static final char HEX_DIGITS [] =
861
903
{'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' };
862
904
863
- private static String encryptSHA1ToString (final byte [] data ) {
864
- return bytes2HexString (encryptSHA1 (data ));
865
- }
866
-
867
- private static byte [] encryptSHA1 (final byte [] data ) {
905
+ private static byte [] hashTemplate (final byte [] data , final String algorithm ) {
868
906
if (data == null || data .length <= 0 ) return null ;
869
907
try {
870
- MessageDigest md = MessageDigest .getInstance ("SHA1" );
908
+ MessageDigest md = MessageDigest .getInstance (algorithm );
871
909
md .update (data );
872
910
return md .digest ();
873
911
} catch (NoSuchAlgorithmException e ) {
0 commit comments