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


Java AESEngine类代码示例

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


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

示例1: aesEncrypt

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public static byte[] aesEncrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
    try {
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        for (int i = 0; i < 32; i++) {
            dhSharedSecret[i] ^= nonce[i];
        }
        byte[] key = sha256().digest(dhSharedSecret);
        byte[] iv = new byte[16];
        secureRandom.get().nextBytes(iv);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(true, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(plaintext.length)];
        int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
        ciphertextLength += aes.doFinal(output, ciphertextLength);
        byte[] result = new byte[iv.length + ciphertextLength];
        System.arraycopy(iv, 0, result, 0, iv.length);
        System.arraycopy(output, 0, result, iv.length, ciphertextLength);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:26,代码来源:Crypto.java

示例2: getFinalKeyDigest

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
/**
 * Create a final key from the parameters passed
 */
public static byte[] getFinalKeyDigest(byte[] key, byte[] masterSeed, byte[] transformSeed, long transformRounds) {

    AESEngine engine = new AESEngine();
    engine.init(true, new KeyParameter(transformSeed));

    // copy input key
    byte[] transformedKey = new byte[key.length];
    System.arraycopy(key, 0, transformedKey, 0, transformedKey.length);

    // transform rounds times
    for (long rounds = 0; rounds < transformRounds; rounds++) {
        engine.processBlock(transformedKey, 0, transformedKey, 0);
        engine.processBlock(transformedKey, 16, transformedKey, 16);
    }

    MessageDigest md = getMessageDigestInstance();
    byte[] transformedKeyDigest = md.digest(transformedKey);

    md.update(masterSeed);
    return md.digest(transformedKeyDigest);
}
 
开发者ID:jorabin,项目名称:KeePassJava2,代码行数:25,代码来源:Encryption.java

示例3: createCipher

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的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

示例4: createAes128CtrPkcs7PaddingCipher

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
static PaddedBufferedBlockCipher createAes128CtrPkcs7PaddingCipher(
        boolean encrypting,
        byte[] iv,
        byte[] key) {
    AESEngine aes = new AESEngine();
    SICBlockCipher aesCtr = new SICBlockCipher(aes);
    PaddedBufferedBlockCipher aesCtrPkcs7 =
            new PaddedBufferedBlockCipher(aesCtr, new PKCS7Padding());
    aesCtrPkcs7.init(encrypting, new ParametersWithIV(new KeyParameter(key), iv));

    return aesCtrPkcs7;
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:13,代码来源:IoUtil.java

示例5: Cmac

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
/**
 * Creates a new instance using the given key and message.
 */

   public Cmac(byte[] key, byte[] message)
{
	this.key = Arrays.copyOf(key, key.length);
	this.message = Arrays.copyOf(message, message.length);

       CMac cmac = new CMac(new AESEngine());
       cmac.init(new KeyParameter(key));
       cmac.update(message,0,message.length);
       this.mac=new byte[16];
       cmac.doFinal(mac,0);
}
 
开发者ID:PIVopacity,项目名称:PIVOpacityDemo-android,代码行数:16,代码来源:Cmac.java

示例6: aesDecrypt

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public static byte[] aesDecrypt(byte[] ivCiphertext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
    try {
        if (ivCiphertext.length < 16 || ivCiphertext.length % 16 != 0) {
            throw new InvalidCipherTextException("invalid ciphertext");
        }
        byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
        byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        for (int i = 0; i < 32; i++) {
            dhSharedSecret[i] ^= nonce[i];
        }
        byte[] key = sha256().digest(dhSharedSecret);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(false, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
        int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
        plaintextLength += aes.doFinal(output, plaintextLength);
        byte[] result = new byte[plaintextLength];
        System.arraycopy(output, 0, result, 0, result.length);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:28,代码来源:Crypto.java

示例7: decrypt

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的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

示例8: encrypt

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的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

示例9: ECIESwithAES

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public ECIESwithAES() {
    super(new AESEngine());
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:4,代码来源:IESCipher.java

示例10: ECIESwithAESCBC

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public ECIESwithAESCBC() {
    super(new CBCBlockCipher(new AESEngine()), 16);
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:4,代码来源:IESCipher.java

示例11: OldECIESwithAES

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public OldECIESwithAES() {
    super(new AESEngine());
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:4,代码来源:IESCipher.java

示例12: OldECIESwithAESCBC

import org.spongycastle.crypto.engines.AESEngine; //导入依赖的package包/类
public OldECIESwithAESCBC() {
    super(new CBCBlockCipher(new AESEngine()), 16);
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:4,代码来源:IESCipher.java


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