Android: Behaviour of PackageInfo.signatures?










0















I have the following implementation:



Signature sigs = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)

Log.i(TAG, "Signature: " + SignatureUtil.getSHA1(sig.toByteArray()));



and...



public class SignatureUtil

public static String getSHA1(byte sig)

MessageDigest digest = null;
try

digest = MessageDigest.getInstance("SHA1", "BC");

catch (Exception e)

try

return new String(sig, "UTF-8");

catch (UnsupportedEncodingException e1)

return new String(sig);


digest.update(sig);
byte hashtext = digest.digest();

return bytesToHex(hashtext);


//util method to convert byte array to hex string
private static String bytesToHex(byte bytes)

final char hexArray = '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F';
char hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++)

v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];

return new String(hexChars);




Currently I have one outcome of this method which could look like this fake example: 174AC857QTVSLK87ACQW3547KHOPP8787QASHI88



I read in this question that this value is unable to spoof or readable by anyone.



My questions:
When I sign with my release key, do I get a different code then or do I get multiple codes?
What happens if anybody hacks my app due to byte manipulation or something else by using some piracy patcher apps? Will this value change then? I guess not. In this case, can I somehow create some 'checksum' of my app (which would surely change from build to build)? (because that's actually what I want to achieve)










share|improve this question






















  • SHA1 is not a signature, it is a hash function.

    – kelalaka
    Nov 14 '18 at 21:23






  • 1





    @kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

    – James K Polk
    Nov 14 '18 at 23:55















0















I have the following implementation:



Signature sigs = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)

Log.i(TAG, "Signature: " + SignatureUtil.getSHA1(sig.toByteArray()));



and...



public class SignatureUtil

public static String getSHA1(byte sig)

MessageDigest digest = null;
try

digest = MessageDigest.getInstance("SHA1", "BC");

catch (Exception e)

try

return new String(sig, "UTF-8");

catch (UnsupportedEncodingException e1)

return new String(sig);


digest.update(sig);
byte hashtext = digest.digest();

return bytesToHex(hashtext);


//util method to convert byte array to hex string
private static String bytesToHex(byte bytes)

final char hexArray = '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F';
char hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++)

v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];

return new String(hexChars);




Currently I have one outcome of this method which could look like this fake example: 174AC857QTVSLK87ACQW3547KHOPP8787QASHI88



I read in this question that this value is unable to spoof or readable by anyone.



My questions:
When I sign with my release key, do I get a different code then or do I get multiple codes?
What happens if anybody hacks my app due to byte manipulation or something else by using some piracy patcher apps? Will this value change then? I guess not. In this case, can I somehow create some 'checksum' of my app (which would surely change from build to build)? (because that's actually what I want to achieve)










share|improve this question






















  • SHA1 is not a signature, it is a hash function.

    – kelalaka
    Nov 14 '18 at 21:23






  • 1





    @kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

    – James K Polk
    Nov 14 '18 at 23:55













0












0








0








I have the following implementation:



Signature sigs = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)

Log.i(TAG, "Signature: " + SignatureUtil.getSHA1(sig.toByteArray()));



and...



public class SignatureUtil

public static String getSHA1(byte sig)

MessageDigest digest = null;
try

digest = MessageDigest.getInstance("SHA1", "BC");

catch (Exception e)

try

return new String(sig, "UTF-8");

catch (UnsupportedEncodingException e1)

return new String(sig);


digest.update(sig);
byte hashtext = digest.digest();

return bytesToHex(hashtext);


//util method to convert byte array to hex string
private static String bytesToHex(byte bytes)

final char hexArray = '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F';
char hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++)

v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];

return new String(hexChars);




Currently I have one outcome of this method which could look like this fake example: 174AC857QTVSLK87ACQW3547KHOPP8787QASHI88



I read in this question that this value is unable to spoof or readable by anyone.



My questions:
When I sign with my release key, do I get a different code then or do I get multiple codes?
What happens if anybody hacks my app due to byte manipulation or something else by using some piracy patcher apps? Will this value change then? I guess not. In this case, can I somehow create some 'checksum' of my app (which would surely change from build to build)? (because that's actually what I want to achieve)










share|improve this question














I have the following implementation:



Signature sigs = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)

Log.i(TAG, "Signature: " + SignatureUtil.getSHA1(sig.toByteArray()));



and...



public class SignatureUtil

public static String getSHA1(byte sig)

MessageDigest digest = null;
try

digest = MessageDigest.getInstance("SHA1", "BC");

catch (Exception e)

try

return new String(sig, "UTF-8");

catch (UnsupportedEncodingException e1)

return new String(sig);


digest.update(sig);
byte hashtext = digest.digest();

return bytesToHex(hashtext);


//util method to convert byte array to hex string
private static String bytesToHex(byte bytes)

final char hexArray = '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F';
char hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++)

v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];

return new String(hexChars);




Currently I have one outcome of this method which could look like this fake example: 174AC857QTVSLK87ACQW3547KHOPP8787QASHI88



I read in this question that this value is unable to spoof or readable by anyone.



My questions:
When I sign with my release key, do I get a different code then or do I get multiple codes?
What happens if anybody hacks my app due to byte manipulation or something else by using some piracy patcher apps? Will this value change then? I guess not. In this case, can I somehow create some 'checksum' of my app (which would surely change from build to build)? (because that's actually what I want to achieve)







android encryption signature






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 20:27









BevorBevor

4,126854104




4,126854104












  • SHA1 is not a signature, it is a hash function.

    – kelalaka
    Nov 14 '18 at 21:23






  • 1





    @kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

    – James K Polk
    Nov 14 '18 at 23:55

















  • SHA1 is not a signature, it is a hash function.

    – kelalaka
    Nov 14 '18 at 21:23






  • 1





    @kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

    – James K Polk
    Nov 14 '18 at 23:55
















SHA1 is not a signature, it is a hash function.

– kelalaka
Nov 14 '18 at 21:23





SHA1 is not a signature, it is a hash function.

– kelalaka
Nov 14 '18 at 21:23




1




1





@kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

– James K Polk
Nov 14 '18 at 23:55





@kelalaka: Unfortunately, Android use the word "signature" to refer to both the hashes of files and the actual APK signature.

– James K Polk
Nov 14 '18 at 23:55












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308254%2fandroid-behaviour-of-packageinfo-signatures%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308254%2fandroid-behaviour-of-packageinfo-signatures%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto