protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver) { if (password.length() > 255) { password = password.substring(0, 255); } HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte hash[] = hashAlg.digest(StringUtil.getToUnicodeLE(password)); byte salt[] = ver.getSalt(); hashAlg.reset(); for (int i = 0; i < 16; i++) { hashAlg.update(hash, 0, 5); hashAlg.update(salt); } hash = new byte[5]; System.arraycopy(hashAlg.digest(), 0, hash, 0, 5); return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver) { if (password.length() > 255) { password = password.substring(0, 255); } HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); hashAlg.update(ver.getSalt()); byte hash[] = hashAlg.digest(StringUtil.getToUnicodeLE(password)); return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver, int keySize) { HashAlgorithm hashAlgo = ver.getHashAlgorithm(); byte pwHash[] = hashPassword(password, hashAlgo, ver.getSalt(), ver.getSpinCount()); byte[] blockKey = new byte[4]; LittleEndian.putInt(blockKey, 0, 0); byte[] finalHash = CryptoFunctions.generateKey(pwHash, hashAlgo, blockKey, hashAlgo.hashSize); byte x1[] = fillAndXor(finalHash, (byte) 0x36); byte x2[] = fillAndXor(finalHash, (byte) 0x5c); byte[] x3 = new byte[x1.length + x2.length]; System.arraycopy(x1, 0, x3, 0, x1.length); System.arraycopy(x2, 0, x3, x1.length, x2.length); byte[] key = Arrays.copyOf(x3, keySize); return new SecretKeySpec(key, ver.getCipherAlgorithm().jceId); }
private Cipher getCipher(SecretKey key, String padding) { EncryptionVerifier ver = getEncryptionInfo().getVerifier(); return CryptoFunctions.getCipher(key, ver.getCipherAlgorithm(), ver.getChainingMode(), null, Cipher.ENCRYPT_MODE, padding); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver) { if (password.length() > 255) { password = password.substring(0, 255); } HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); hashAlg.update(ver.getSalt()); byte hash[] = hashAlg.digest(StringUtil.getToUnicodeLE(password)); return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver) { if (password.length() > 255) { password = password.substring(0, 255); } HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte hash[] = hashAlg.digest(StringUtil.getToUnicodeLE(password)); byte salt[] = ver.getSalt(); hashAlg.reset(); for (int i = 0; i < 16; i++) { hashAlg.update(hash, 0, 5); hashAlg.update(salt); } hash = new byte[5]; System.arraycopy(hashAlg.digest(), 0, hash, 0, 5); return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver, int keySize) { HashAlgorithm hashAlgo = ver.getHashAlgorithm(); byte pwHash[] = hashPassword(password, hashAlgo, ver.getSalt(), ver.getSpinCount()); byte[] blockKey = new byte[4]; LittleEndian.putInt(blockKey, 0, 0); byte[] finalHash = CryptoFunctions.generateKey(pwHash, hashAlgo, blockKey, hashAlgo.hashSize); byte x1[] = fillAndXor(finalHash, (byte) 0x36); byte x2[] = fillAndXor(finalHash, (byte) 0x5c); byte[] x3 = new byte[x1.length + x2.length]; System.arraycopy(x1, 0, x3, 0, x1.length); System.arraycopy(x2, 0, x3, x1.length, x2.length); byte[] key = Arrays.copyOf(x3, keySize); return new SecretKeySpec(key, ver.getCipherAlgorithm().jceId); }
private Cipher getCipher(SecretKey key, String padding) { EncryptionVerifier ver = getEncryptionInfo().getVerifier(); return CryptoFunctions.getCipher(key, ver.getCipherAlgorithm(), ver.getChainingMode(), null, Cipher.ENCRYPT_MODE, padding); }