private void initializeKeyEncryptionKey(FileSystem fs, Path pathToKey, CryptoModuleParameters params) throws IOException { DataOutputStream out = null; try { out = fs.create(pathToKey); // Very important, lets hedge our bets fs.setReplication(pathToKey, (short) 5); SecureRandom random = DefaultCryptoModuleUtils.getSecureRandom( params.getRandomNumberGenerator(), params.getRandomNumberGeneratorProvider()); int keyLength = params.getKeyLength(); byte[] newRandomKeyEncryptionKey = new byte[keyLength / 8]; random.nextBytes(newRandomKeyEncryptionKey); out.writeInt(newRandomKeyEncryptionKey.length); out.write(newRandomKeyEncryptionKey); out.flush(); } finally { if (out != null) { out.close(); } } }
@Override public CryptoModuleParameters generateNewRandomSessionKey(CryptoModuleParameters params) { if (params.getSecureRandom() == null) { params.setSecureRandom(DefaultCryptoModuleUtils.getSecureRandom( params.getRandomNumberGenerator(), params.getRandomNumberGeneratorProvider())); } byte[] newSessionKey = new byte[params.getKeyLength() / 8]; params.getSecureRandom().nextBytes(newSessionKey); params.setPlaintextKey(newSessionKey); return params; }
SecureRandom random = DefaultCryptoModuleUtils.getSecureRandom( params.getRandomNumberGenerator(), params.getRandomNumberGeneratorProvider()); int keyLength = params.getKeyLength(); byte[] newRandomKeyEncryptionKey = new byte[keyLength / 8]; random.nextBytes(newRandomKeyEncryptionKey);
"Using cipher suite \"%s\" with key length %d with" + " RNG \"%s\" and RNG provider \"%s\" and key encryption strategy" + " \"%s\"", cipherTransformation, params.getKeyLength(), params.getRandomNumberGenerator(), params.getRandomNumberGeneratorProvider(), params.getKeyEncryptionStrategyClass()));
byte[] randomKey = new byte[params.getKeyLength() / 8]; secureRandom.nextBytes(randomKey); params.setPlaintextKey(randomKey);
allIsWell = validateNotZero(params.getKeyLength(), allIsWell, errorBuf, "No key length was specified."); allIsWell = validateNotEmpty(params.getEncryptionMode(), allIsWell, errorBuf, allIsWell = validateNotZero(params.getKeyLength(), allIsWell, errorBuf, "No key length was specified."); allIsWell = validateNotEmpty(params.getEncryptionMode(), allIsWell, errorBuf,