Class SigningBlockUtils


  • public final class SigningBlockUtils
    extends java.lang.Object
    Generates and appends a new block to APK v2 Signature block.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] addToSigningBlock​(byte[] signingBlock, byte[] blockValue, int blockId)
      Generates a new block with the given block value and block id, and appends it to the signing block.
      static java.nio.ByteBuffer extractBlock​(java.io.File apk, int blockId)
      Extract a block with the given id from the APK.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addToSigningBlock

        public static byte[] addToSigningBlock​(byte[] signingBlock,
                                               byte[] blockValue,
                                               int blockId)
                                        throws java.io.IOException
        Generates a new block with the given block value and block id, and appends it to the signing block.
        Parameters:
        signingBlock - Block containing v2 signature and (optionally) padding block or null.
        blockValue - byte array containing block value of the new block or null.
        blockId - block id of the new block.
        Returns:
        APK v2 block with signatures and the new block. If blockValue is null the signingBlock is returned without any modification. If signingBlock is null, a new signature block is created containing the new block and, optionally, padding block.
        Throws:
        java.io.IOException
      • extractBlock

        @Nullable
        public static java.nio.ByteBuffer extractBlock​(java.io.File apk,
                                                       int blockId)
                                                throws java.io.IOException,
                                                       com.android.apksig.zip.ZipFormatException,
                                                       com.android.apksig.apk.ApkSigningBlockNotFoundException
        Extract a block with the given id from the APK. If there is more than one block with the same ID, the first block will be returned. If there are no block with the give id, null will be returned.
        Parameters:
        apk - APK file
        blockId - id of the block to be extracted.
        Throws:
        java.io.IOException
        com.android.apksig.zip.ZipFormatException
        com.android.apksig.apk.ApkSigningBlockNotFoundException