コード例 #1
0
  /**
   * Calculates keyed checksum.
   *
   * @param data the data used to generate the checksum.
   * @param size length of the data.
   * @param key the key used to encrypt the checksum.
   * @return keyed checksum.
   */
  public byte[] calculateKeyedChecksum(byte[] data, int size, byte[] key, int usage)
      throws KrbCryptoException {

    try {
      return Aes128.calculateChecksum(key, usage, data, 0, size);
    } catch (GeneralSecurityException e) {
      KrbCryptoException ke = new KrbCryptoException(e.getMessage());
      ke.initCause(e);
      throw ke;
    }
  }
コード例 #2
0
  /**
   * Verifies keyed checksum.
   *
   * @param data the data.
   * @param size the length of data.
   * @param key the key used to encrypt the checksum.
   * @param checksum
   * @return true if verification is successful.
   */
  public boolean verifyKeyedChecksum(byte[] data, int size, byte[] key, byte[] checksum, int usage)
      throws KrbCryptoException {

    try {
      byte[] newCksum = Aes128.calculateChecksum(key, usage, data, 0, size);
      return isChecksumEqual(checksum, newCksum);
    } catch (GeneralSecurityException e) {
      KrbCryptoException ke = new KrbCryptoException(e.getMessage());
      ke.initCause(e);
      throw ke;
    }
  }