当前位置: 首页>>代码示例>>Java>>正文


Java PKCS5S2ParametersGenerator类代码示例

本文整理汇总了Java中org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator的典型用法代码示例。如果您正苦于以下问题:Java PKCS5S2ParametersGenerator类的具体用法?Java PKCS5S2ParametersGenerator怎么用?Java PKCS5S2ParametersGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PKCS5S2ParametersGenerator类属于org.spongycastle.crypto.generators包,在下文中一共展示了PKCS5S2ParametersGenerator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCipher

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
protected PaddedBufferedBlockCipher createCipher(String passphrase, boolean isEncrypting) throws CryptoException{
	CustomRandom cRandom = new CustomRandom(utf8Bytes(passphrase));
	byte[] salt = new byte[8];
	cRandom.nextBytes(salt);
	byte[] password = new byte[32];
	cRandom.nextBytes(password);
	int iterationCount = 1000;
	int keyLength = 256;		
	int blockSize = 128;
	
	PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest());
	generator.init(password, salt, iterationCount);

	CipherParameters key = generator
				.generateDerivedParameters(keyLength, blockSize);
	
	CBCBlockCipher cbcCipher = new CBCBlockCipher(new AESEngine());
	PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
			cbcCipher, new PKCS7Padding());
	cipher.init(isEncrypting, key);
	return cipher;
}
 
开发者ID:micheal-swiggs,项目名称:jumblar,代码行数:23,代码来源:WeakSymmetricEncryption.java

示例2: createKey

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
private KeyParameter createKey(String password, byte[] salt,
		int iterations, int keySizeInBits) {
	//System.out.println(keySizeInBits);
	//System.out.println(iterations);
	//System.out.println(salt);
	//System.out.println(password);
	
	PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(
			new SHA256Digest());
	generator.init(
			PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray()), 
			salt, 
			iterations);
	KeyParameter key = (KeyParameter) generator
			.generateDerivedMacParameters(keySizeInBits);
	return key;
}
 
开发者ID:AurionFinancial,项目名称:AndroidWallet,代码行数:18,代码来源:Blobvault.java

示例3: pbkdf2

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
private byte[] pbkdf2(String password, byte[] salt, int iterations) {
	byte[] utf8 = StringUtils.toUtf8(password);
	Digest digest = new SHA256Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(utf8, salt, iterations);
	int keyLengthInBits = SecretKey.LENGTH * 8;
	CipherParameters p = gen.generateDerivedParameters(keyLengthInBits);
	return ((KeyParameter) p).getKey();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:10,代码来源:CryptoComponentImpl.java

示例4: sampleRunningTime

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
private long sampleRunningTime(int iterations) {
	byte[] password = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
	byte[] salt = new byte[PBKDF_SALT_BYTES];
	int keyLengthInBits = SecretKey.LENGTH * 8;
	long start = System.nanoTime();
	Digest digest = new SHA256Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(password, salt, iterations);
	gen.generateDerivedParameters(keyLengthInBits);
	return System.nanoTime() - start;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:12,代码来源:CryptoComponentImpl.java

示例5: pbkdf2

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
private byte[] pbkdf2(char[] password, byte[] salt, int iterations) {
	byte[] utf8 = toUtf8ByteArray(password);
	Digest digest = new SHA384Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(utf8, salt, iterations);
	int keyLengthInBits = CIPHER_KEY_BYTES * 8;
	CipherParameters p = gen.generateDerivedParameters(keyLengthInBits);
	ByteUtils.erase(utf8);
	return ((KeyParameter) p).getKey();
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:11,代码来源:CryptoComponentImpl.java

示例6: sampleRunningTime

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
private long sampleRunningTime(int iterations) {
	byte[] password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
	byte[] salt = new byte[PBKDF_SALT_BYTES];
	int keyLengthInBits = CIPHER_KEY_BYTES * 8;
	long start = System.nanoTime();
	Digest digest = new SHA384Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(password, salt, iterations);
	gen.generateDerivedParameters(keyLengthInBits);
	return System.nanoTime() - start;
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:12,代码来源:CryptoComponentImpl.java

示例7: generateHash

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
/**
 * @summary Method to generate a key-stretched password from
 *          a seed password (hashed) and a salt.
 * @return  {String} The encoded generated key-stretched password.
 */
public static String generateHash(final byte[] seedSHA,
                                  final byte[] salt,
                                  final Integer iterations,
                                  final Integer specialCharsFlag)
    throws UnsupportedEncodingException {
    byte[] hash = null;
    PKCS5S2ParametersGenerator generator =
        new PKCS5S2ParametersGenerator(new SHA256Digest());

    generator.init(seedSHA,
                   salt,
                   iterations);

    hash = ((KeyParameter)
            generator.generateDerivedParameters(256)).getKey();

    String encodedHash = null;
    if (specialCharsFlag.equals(1)) {
        encodedHash = Z85.Z85Encoder(hash);
    } else {
        try {
            encodedHash = new String(Base64.encode(hash), UTF8);
        } catch (UnsupportedEncodingException e) {
            // Throw it to the caller
            throw e;
        }
    }

    return encodedHash;
}
 
开发者ID:manzdagratiano,项目名称:gobbledygook,代码行数:36,代码来源:Crypto.java

示例8: decrypt

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
public static String decrypt(String ciphertext, String password, final int PBKDF2Iterations) throws Exception {
	byte[] cipherdata = Base64.decode(ciphertext, Base64.NO_WRAP);

	//Sperate the IV and cipher data
	byte[] iv = copyOfRange(cipherdata, 0, AESBlockSize * 4);
	byte[] input = copyOfRange(cipherdata, AESBlockSize * 4, cipherdata.length);

	PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
	generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray()), iv, PBKDF2Iterations);
	KeyParameter keyParam = (KeyParameter)generator.generateDerivedParameters(256);

	CipherParameters params = new ParametersWithIV(keyParam, iv);

	// setup AES cipher in CBC mode with PKCS7 padding
	BlockCipherPadding padding = new ISO10126d2Padding();
	BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
	cipher.reset();
	cipher.init(false, params);

	// create a temporary buffer to decode into (it'll include padding)
	byte[] buf = new byte[cipher.getOutputSize(input.length)];
	int len = cipher.processBytes(input, 0, input.length, buf, 0);
	len += cipher.doFinal(buf, len);

	// remove padding
	byte[] out = new byte[len];
	System.arraycopy(buf, 0, out, 0, len);

	// return string representation of decoded bytes
	return new String(out, "UTF-8"); 
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:32,代码来源:MyWallet.java

示例9: encrypt

import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; //导入依赖的package包/类
public static String encrypt(String text, String password, final int PBKDF2Iterations) throws Exception {

		if (password == null)
			throw new Exception("You must provide an ecryption password");

		// Use secure random to generate a 16 byte iv
		SecureRandom random = new SecureRandom();
		byte iv[] = new byte[AESBlockSize * 4];
		random.nextBytes(iv);

		byte[] textbytes = text.getBytes("UTF-8");

		PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
		generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray()), iv, PBKDF2Iterations);
		KeyParameter keyParam = (KeyParameter)generator.generateDerivedParameters(256);

		CipherParameters params = new ParametersWithIV(keyParam, iv);

		// setup AES cipher in CBC mode with PKCS7 padding
		BlockCipherPadding padding = new ISO10126d2Padding();
		BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
		cipher.reset();
		cipher.init(true, params);

		byte[] outBuf = cipherData(cipher, textbytes);

		// Append to IV to the output
		byte[] ivAppended = ArrayUtils.addAll(iv, outBuf);

		return new String(Base64.encode(ivAppended, Base64.NO_WRAP), "UTF-8");
	}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:32,代码来源:MyWallet.java


注:本文中的org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。