Example usage for org.bouncycastle.util Arrays areEqual

List of usage examples for org.bouncycastle.util Arrays areEqual

Introduction

In this page you can find the example usage for org.bouncycastle.util Arrays areEqual.

Prototype

public static boolean areEqual(short[] a, short[] b) 

Source Link

Usage

From source file:org.thoughtcrime.securesms.crypto.KeyExchangeProcessor.java

License:Open Source License

public boolean isRemoteKeyExchangeForExistingSession(KeyExchangeMessage message) {
    return Arrays.areEqual(message.getPublicKey().getFingerprintBytes(), sessionRecord.getRemoteFingerprint());
}

From source file:org.thoughtcrime.securesms.crypto.KeyExchangeProcessor.java

License:Open Source License

public boolean isLocalKeyExchangeForExistingSession(KeyExchangeMessage message) {
    return Arrays.areEqual(message.getPublicKey().getFingerprintBytes(), sessionRecord.getLocalFingerprint());
}

From source file:org.waveprotocol.box.server.persistence.blocks.impl.RecorderTest.java

License:Apache License

public void testRecordOutputAndInput() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    Recorder.writeInt(out, 1);/*from   w  ww  . j  a va2s.co m*/
    Recorder.writeInt(out, 0xFF);
    Recorder.writeInt(out, 0x12345678);

    byte[] bytes = "qwerty".getBytes();
    Recorder.writeRecord(out, bytes);

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());

    assertEquals(1, Recorder.readInt(in));
    assertEquals(0xFF, Recorder.readInt(in));
    assertEquals(0x12345678, Recorder.readInt(in));

    assertTrue(Arrays.areEqual(bytes, Recorder.readRecord(in)));
}

From source file:se.altrusoft.docserv.integ.IntegrationTest.java

License:Mozilla Public License

void assertResponseEqualsFileContent(File expectedFile, Promise<Response> response, boolean onlyVerifySize) {
    FileInputStream expectedInputStream = null;
    InputStream actualInputStream = null;
    try {/*from ww w  . j a  v  a2 s .  c  o m*/
        expectedInputStream = FileUtils.openInputStream(expectedFile);
        byte[] expectedByteArray = IOUtils.toByteArray(expectedInputStream);

        actualInputStream = response.get().getBodyAsStream();
        byte[] actualByteArray = IOUtils.toByteArray(actualInputStream);

        // We only verify PDF files by raw text. This because we are
        // depending on external OpenOffice lib while
        // executing this test, and we can't be too pedantic about the
        // details then (different OO versions
        // generate slightly different files)
        if (expectedFile.getName().endsWith(".pdf")) {
            String expectedPageOne = getNonWhiteSpacesFromPDF(expectedByteArray);
            String actualPageOne = getNonWhiteSpacesFromPDF(actualByteArray);
            assertEquals("Not same text on first page", expectedPageOne, actualPageOne);
        } else {
            if (onlyVerifySize) {
                boolean hasGeneratedFileCorrectSize = (expectedByteArray.length == actualByteArray.length);
                if (!hasGeneratedFileCorrectSize) {
                    fail("Actual file is not same size expected (exp size="
                            + new String(expectedByteArray).length() + " act size="
                            + new String(actualByteArray).length());
                }
            } else {
                if (!Arrays.areEqual(expectedByteArray, actualByteArray)) {
                    fail("Actual file has not same content as expected (exp size="
                            + new String(expectedByteArray).length() + " act size="
                            + new String(actualByteArray).length());
                }
            }
        }
    } catch (IOException e) {
        fail("Can't compare generated file with expected file: " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(expectedInputStream);
        IOUtils.closeQuietly(actualInputStream);
    }
}

From source file:secret.sharing.Encryptor.java

License:Open Source License

/**
 * Checks if HMAC provided by the encryption header is equally with the calculated HMAC
 * @return True if both are equal, otherwise false
 *///from   ww w  .  j  a va2 s  .c  o m
public boolean IsHMACValid() {
    byte[] curHMAC = GetHMAC();
    if (curHMAC != null && mParsedHMAC != null)
        return Arrays.areEqual(curHMAC, mParsedHMAC);
    return false;
}

From source file:sernet.verinice.encryption.test.CryptoTest.java

License:Open Source License

@Test
public void VNAPBCryptoTest() throws SyncParameterException, IOException, CommandException {
    byte[] plainContent = FileUtil.getFileData(new File(getAbsoluteFilePath(VNA_FILE)));
    char[] password = getPassword(10);
    byte[] encryptedContent = getEncryptionService().encrypt(plainContent, password);
    byte[] decryptedContent = getEncryptionService().decrypt(encryptedContent, password);
    assertTrue(Arrays.areEqual(plainContent, decryptedContent));
}

From source file:us.eharning.atomun.keygen.internal.spi.bip0032.BouncyCastleBIP0032NodeProcessor.java

License:Apache License

/**
 * Convert the Base58+checksum encoded string into a BIP0032 node.
 *
 * @param serialized//from  w  w w  .  j a v  a  2s  .com
 *         encoded string to decode.
 *
 * @return BIP0032 node represented by the serialized string.
 *
 * @throws ValidationException
 *         if the data is not a valid encoded BIP0032 node.
 */
@Override
public BIP0032Node importNode(String serialized) throws ValidationException {
    byte[] data = Base58.decodeWithChecksum(serialized);
    if (data.length != 78) {
        throw new ValidationException("Invalid extended key value");
    }
    byte[] type = Arrays.copyOf(data, 4);
    boolean hasPrivate;
    if (Arrays.areEqual(type, xprv) || Arrays.areEqual(type, tprv)) {
        hasPrivate = true;
    } else if (Arrays.areEqual(type, xpub) || Arrays.areEqual(type, tpub)) {
        hasPrivate = false;
    } else {
        throw new ValidationException("Invalid magic number for an extended key");
    }
    int depth = data[4] & 0xff;
    int parent = getInt32(data, 5);
    int sequence = getInt32(data, 9);
    byte[] chainCode = Arrays.copyOfRange(data, 13, 13 + 32);
    byte[] pubOrPriv = Arrays.copyOfRange(data, 13 + 32, data.length);
    ECKey key;
    if (hasPrivate) {
        key = ECKeyFactory.getInstance().fromSecretExponent(new BigInteger(1, pubOrPriv), true);
    } else {
        key = ECKeyFactory.getInstance().fromEncodedPublicKey(pubOrPriv, true);
    }
    return new BIP0032Node(key, chainCode, depth, parent, sequence);
}

From source file:Utils.bytes.Bytes.java

@Override
public boolean equals(Object b) {
    if (b instanceof Bytes) {
        return Arrays.areEqual(bytes, ((Bytes) b).getBytes());
    } else {//from w  w w.jav  a  2s  .co m
        return false;
    }
}