Package com.google.nigori.common

Examples of com.google.nigori.common.NigoriCryptographyException


    try {
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
      KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount);
      return factory.generateSecret(spec).getEncoded();
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    } catch (InvalidKeySpecException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here


      Mac mac = Mac.getInstance(hmacAlgorithm);
      SecretKey key = new SecretKeySpec(secretKey, NigoriConstants.A_KMAC);
      mac.init(key);
      return mac.doFinal(message);
    } catch (Exception e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

    byte[] mac = new byte[NigoriConstants.B_MAC];
    Cipher cipher;
    try {
      cipher = Cipher.getInstance(NigoriConstants.A_SYMENC_CIPHER);
    } catch (NoSuchPaddingException e) {
      throw new NigoriCryptographyException(e);
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    }

    if (ciphertext.length < iv.length + mac.length + cipher.getBlockSize()) {
      throw new NigoriCryptographyException(
          "Ciphertext is too short to be a valid encrypted message.");
    }

    byte[] data = new byte[ciphertext.length - iv.length - mac.length];
    System.arraycopy(ciphertext, 0, iv, 0, iv.length);
    System.arraycopy(ciphertext, ciphertext.length - mac.length, mac, 0, mac.length);
    System.arraycopy(ciphertext, iv.length, data, 0, data.length);

    byte[] macCheck = generateCipherHMAC(data);
    if (mac.length != macCheck.length) {
      throw new NigoriCryptographyException(String.format(
          "Length mismatch between provided (%d) and received (%d) HMACs.", mac.length,
          macCheck.length));
    }

    for (int i = 0; i < macCheck.length; i++) {
      if (mac[i] != macCheck[i]) {
        throw new NigoriCryptographyException("HMAC of ciphertext does not match expected value");
      }
    }

    try {
      SecretKey key = new SecretKeySpec(encryptionKey, NigoriConstants.A_SYMENC);
      cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
      return cipher.doFinal(data);
    } catch (InvalidAlgorithmParameterException e) {
      throw new NigoriCryptographyException(e);
    } catch (InvalidKeyException e) {
      throw new NigoriCryptographyException(e);
    } catch (BadPaddingException e) {
      throw new NigoriCryptographyException(e);
    } catch (IllegalBlockSizeException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

      System.arraycopy(data, 0, ciphertext, iv.length, data.length);
      System.arraycopy(mac, 0, ciphertext, iv.length + data.length, mac.length);

      return ciphertext;
    } catch (NoSuchPaddingException e) {
      throw new NigoriCryptographyException(e);
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    } catch (InvalidAlgorithmParameterException e) {
      throw new NigoriCryptographyException(e);
    } catch (InvalidKeyException e) {
      throw new NigoriCryptographyException(e);
    } catch (BadPaddingException e) {
      throw new NigoriCryptographyException(e);
    } catch (IllegalBlockSizeException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

  @Override
  public DSASign signer() throws NigoriCryptographyException {
    try {
      return new DSASign(userSecretKey);
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

      byte[] revBytes = new byte[HASH_SIZE + idBytes.length];
      System.arraycopy(hashBytes, 0, revBytes, 0, HASH_SIZE);
      System.arraycopy(idBytes, 0, revBytes, HASH_SIZE, idBytes.length);
      return revBytes;
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

  @Override
  public DSASign signer() throws NigoriCryptographyException {
    try {
      return new DSASign(userSecretKey);
    } catch (NoSuchAlgorithmException e) {
      throw new NigoriCryptographyException(e);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.nigori.common.NigoriCryptographyException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.