Search in sources :

Example 1 with DigestException

use of java.security.DigestException in project hbase by apache.

the class Encryption method hash128.

/**
   * Return the MD5 digest of the concatenation of the supplied arguments.
   */
public static byte[] hash128(byte[]... args) {
    byte[] result = new byte[16];
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        for (byte[] arg : args) {
            md.update(arg);
        }
        md.digest(result, 0, result.length);
        return result;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (DigestException e) {
        throw new RuntimeException(e);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 2 with DigestException

use of java.security.DigestException in project hbase by apache.

the class Encryption method hash128.

/**
   * Return the MD5 digest of the concatenation of the supplied arguments.
   */
public static byte[] hash128(String... args) {
    byte[] result = new byte[16];
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        for (String arg : args) {
            md.update(Bytes.toBytes(arg));
        }
        md.digest(result, 0, result.length);
        return result;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (DigestException e) {
        throw new RuntimeException(e);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 3 with DigestException

use of java.security.DigestException in project walle by Meituan-Dianping.

the class V2SchemeSigner method generateApkSigningBlock.

/**
     * Signs the provided APK using APK Signature Scheme v2 and returns the APK Signing Block
     * containing the signature.
     *
     * @param signerConfigs signer configurations, one for each signer At least one signer config
     *        must be provided.
     *
     * @throws IOException if an I/O error occurs
     * @throws InvalidKeyException if a signing key is not suitable for this signature scheme or
     *         cannot be used in general
     * @throws SignatureException if an error occurs when computing digests of generating
     *         signatures
     */
public static byte[] generateApkSigningBlock(DataSource beforeCentralDir, DataSource centralDir, DataSource eocd, List<SignerConfig> signerConfigs) throws IOException, InvalidKeyException, SignatureException {
    if (signerConfigs.isEmpty()) {
        throw new IllegalArgumentException("No signer configs provided. At least one is required");
    }
    // Figure out which digest(s) to use for APK contents.
    Set<ContentDigestAlgorithm> contentDigestAlgorithms = new HashSet<>(1);
    for (SignerConfig signerConfig : signerConfigs) {
        for (SignatureAlgorithm signatureAlgorithm : signerConfig.signatureAlgorithms) {
            contentDigestAlgorithms.add(signatureAlgorithm.getContentDigestAlgorithm());
        }
    }
    // Ensure that, when digesting, ZIP End of Central Directory record's Central Directory
    // offset field is treated as pointing to the offset at which the APK Signing Block will
    // start.
    long centralDirOffsetForDigesting = beforeCentralDir.size();
    ByteBuffer eocdBuf = ByteBuffer.allocate((int) eocd.size());
    eocdBuf.order(ByteOrder.LITTLE_ENDIAN);
    eocd.copyTo(0, (int) eocd.size(), eocdBuf);
    eocdBuf.flip();
    ZipUtils.setZipEocdCentralDirectoryOffset(eocdBuf, centralDirOffsetForDigesting);
    // Compute digests of APK contents.
    // digest algorithm ID -> digest
    Map<ContentDigestAlgorithm, byte[]> contentDigests;
    try {
        contentDigests = computeContentDigests(contentDigestAlgorithms, new DataSource[] { beforeCentralDir, centralDir, DataSources.asDataSource(eocdBuf) });
    } catch (IOException e) {
        throw new IOException("Failed to read APK being signed", e);
    } catch (DigestException e) {
        throw new SignatureException("Failed to compute digests of APK", e);
    }
    // Sign the digests and wrap the signatures and signer info into an APK Signing Block.
    return generateApkSigningBlock(signerConfigs, contentDigests);
}
Also used : IOException(java.io.IOException) SignatureException(java.security.SignatureException) ByteBuffer(java.nio.ByteBuffer) DataSource(com.android.apksigner.core.util.DataSource) DigestException(java.security.DigestException) HashSet(java.util.HashSet)

Example 4 with DigestException

use of java.security.DigestException in project robovm by robovm.

the class DigestExceptionTest method testDigestException07.

/**
     * Test for <code>DigestException(String, Throwable)</code> constructor
     * Assertion: constructs DigestException when <code>cause</code> is null
     * <code>msg</code> is not null
     */
public void testDigestException07() {
    DigestException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new DigestException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : DigestException(java.security.DigestException)

Example 5 with DigestException

use of java.security.DigestException in project robovm by robovm.

the class DigestExceptionTest method testDigestException08.

/**
     * Test for <code>DigestException(String, Throwable)</code> constructor
     * Assertion: constructs DigestException when <code>cause</code> is not
     * null <code>msg</code> is null
     */
public void testDigestException08() {
    DigestException tE = new DigestException(null, tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() must should ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : DigestException(java.security.DigestException)

Aggregations

DigestException (java.security.DigestException)30 MessageDigest (java.security.MessageDigest)18 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 IOException (java.io.IOException)7 DataSource (com.android.apksigner.core.util.DataSource)3 ByteBuffer (java.nio.ByteBuffer)2 MyMessageDigest1 (org.apache.harmony.security.tests.support.MyMessageDigest1)2 LimitedLengthInputStream (android.content.pm.LimitedLengthInputStream)1 MacAuthenticatedInputStream (android.content.pm.MacAuthenticatedInputStream)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 ByteBufferDataSource (com.android.apksigner.core.internal.util.ByteBufferDataSource)1 MessageDigestSink (com.android.apksigner.core.internal.util.MessageDigestSink)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SignatureException (java.security.SignatureException)1 HashMap (java.util.HashMap)1