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


Java KeyGenerator.getInstance方法代码示例

本文整理汇总了Java中javax.crypto.KeyGenerator.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java KeyGenerator.getInstance方法的具体用法?Java KeyGenerator.getInstance怎么用?Java KeyGenerator.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.KeyGenerator的用法示例。


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

示例1: initFingerprintManager

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private void initFingerprintManager() throws Throwable {
    mFpManager = (FingerprintManager) mContext.getSystemService(Context.FINGERPRINT_SERVICE);
    if (!mFpManager.isHardwareDetected())
        throw new IllegalStateException("Fingerprint hardware not present");

    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    KeyGenerator keyGenerator = KeyGenerator.getInstance(
            KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
    keyStore.load(null);
    keyGenerator.init(new KeyGenParameterSpec.Builder(
            KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
            .build());
    keyGenerator.generateKey();

    Cipher cipher = Cipher.getInstance(
            KeyProperties.KEY_ALGORITHM_AES + "/" +
            KeyProperties.BLOCK_MODE_CBC + "/" +
            KeyProperties.ENCRYPTION_PADDING_PKCS7);
    SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
    cipher.init(Cipher.ENCRYPT_MODE, key);

    mFpHandler = new FingerprintHandler(cipher);

    if (DEBUG) log("Fingeprint manager initialized");
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:28,代码来源:FingerprintLauncher.java

示例2: getSecretKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
public static SecretKey getSecretKey(String secretKey) throws Exception
{
	// 返回生成指定算法的秘密密钥的 KeyGenerator 对象
	KeyGenerator kg = KeyGenerator.getInstance(ENCRYPT_TYPE);

	// 初始化此密钥生成器,使其具有确定的密钥大小
	SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
	random.setSeed(secretKey.getBytes());
	kg.init(56, random);

	// 生成一个密钥
	byte[] key = kg.generateKey().getEncoded();

	// 实例化DES密钥规则
	DESKeySpec dks = new DESKeySpec(key);
	// 实例化密钥工厂
	SecretKeyFactory skf = SecretKeyFactory.getInstance(ENCRYPT_TYPE);
	// 生成密钥
	return skf.generateSecret(dks);
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:21,代码来源:DESUtils.java

示例3: GCMParameterSpecTest

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * Initialize IV, IV with offset, plain text, AAD and SecretKey
 *
 * @param keyLength length of a secret key
 * @param tagLength tag length
 * @param IVlength IV length
 * @param offset offset in a buffer for IV
 * @param textLength plain text length
 * @param AADLength AAD length
 */
public GCMParameterSpecTest(int keyLength, int tagLength, int IVlength,
        int offset, int textLength, int AADLength)
        throws NoSuchAlgorithmException, NoSuchProviderException {
    this.tagLength = tagLength; // save tag length
    this.IVlength = IVlength; // save IV length
    this.offset = offset; // save IV offset

    // prepare IV
    IV = Helper.generateBytes(IVlength);

    // prepare IV with offset
    IVO = new byte[this.IVlength + this.offset];
    System.arraycopy(IV, 0, IVO, offset, this.IVlength);

    // prepare data
    data = Helper.generateBytes(textLength);

    // prepare AAD
    AAD = Helper.generateBytes(AADLength);

    // init a secret key
    KeyGenerator kg = KeyGenerator.getInstance("AES", "SunJCE");
    kg.init(keyLength);
    key = kg.generateKey();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:GCMParameterSpecTest.java

示例4: createInstance

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
@Override
protected SecretKey createInstance() throws Exception {
    if (secureRandom == null) {
        final SecureRandomFactory secureRandomFactory = new SecureRandomFactory();
        secureRandomFactory.setProvider(provider);
        secureRandomFactory.afterPropertiesSet();
        secureRandom = secureRandomFactory.createInstance();
    }
    final KeyGenerator kg;
    if (provider == null) {
        kg = KeyGenerator.getInstance(algorithm);
    } else {
        kg = KeyGenerator.getInstance(algorithm, provider);
    }
    kg.init(keySize, secureRandom);
    return kg.generateKey();
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:18,代码来源:GeneratedSecretKeyFactory.java

示例5: initHmacMD2Key

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 初始化HmacMD2密钥
 * 
 * @return byte[] 密钥
 * @throws Exception
 */
public static byte[] initHmacMD2Key() throws Exception {
	// 初始化KeyGenerator
	KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD2");
	// 产生秘密密钥
	SecretKey secretKey = keyGenerator.generateKey();
	// 获得密钥
	return secretKey.getEncoded();
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:15,代码来源:HmacCoder.java

示例6: generateValues

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private void generateValues() throws Exception {
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
    keyGenerator.init(RandomValuesProvider.getRandomKeyLength());
    radix = Defaults.ALPHABET.radix();
    key = keyGenerator.generateKey().getEncoded();
    input = RandomValuesProvider.randomPlainTextOfBasicDomain();
    values = RandomValuesProvider.valuesAsString(input, key, radix);
}
 
开发者ID:idealista,项目名称:format-preserving-encryption-java,代码行数:9,代码来源:FormatPreservingEncryptionRandomPlainTextAndKeysShould.java

示例7: initKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 產生金鑰
 * KeyGenerator.getInstance
 *      Returns a KeyGenerator object that generates secret keys for the specified algorithm.
 * SecretKey.getEncoded
 *      Returns the key in its primary encoding format
 */
public static byte[] initKey() throws Exception {
    KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORTHM);
    //KeyGenerator.getInstance(algorithm);
    kg.init(128);
    //128, 192, 256
    SecretKey secretKey = kg.generateKey();

    return secretKey.getEncoded();
}
 
开发者ID:48763,项目名称:File-Cipher,代码行数:17,代码来源:AES.java

示例8: getAESKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private SecretKey getAESKey(int bits) {
	try {
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		keyGen.init(bits);
		return keyGen.generateKey();
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:10,代码来源:JWTValidatorTest.java

示例9: initKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 生成密钥
 *
 * @param keysize
 * @return
 */
public byte[] initKey(int keysize) {
    KeyGenerator keyGen = null;
    try {
        keyGen = KeyGenerator.getInstance("DES");
        keyGen.init(keysize);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    SecretKey secretKey = keyGen.generateKey();
    return secretKey.getEncoded();
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:18,代码来源:DESUtils.java

示例10: initHmacSHAKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
/**
 * 初始化HmacSHA1密钥
 *
 * @return
 * @throws Exception
 */
public static byte[] initHmacSHAKey() throws Exception {
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HMacTiger");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:15,代码来源:HmacCoder.java

示例11: Encryptor

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private Encryptor(String algorithm) throws NoSuchAlgorithmException, NoSuchPaddingException
{
    keyGen = KeyGenerator.getInstance(algorithm);
    key = keyGen.generateKey();
    
    cipher = Cipher.getInstance(algorithm);
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:8,代码来源:Encryptor.java

示例12: encrypt

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private byte[] encrypt(byte[] content, byte[] password) {
    try {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        kgen.init(128, new SecureRandom(password));
        SecretKey secretKey = kgen.generateKey();
        byte[] enCodeFormat = secretKey.getEncoded();
        SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return cipher.doFinal(content);
    } catch (Exception e) {
        logger.Erro(this.getClass().getName(), "加密失败!");
    }
    return null;
}
 
开发者ID:Thoxvi,项目名称:WarriorsClipboard_Client_Test,代码行数:16,代码来源:Security.java

示例13: generateRandomAesKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
public static String generateRandomAesKey(int keysize) throws NoSuchAlgorithmException {
    KeyGenerator keyGen = KeyGenerator.getInstance("AES");
    keyGen.init(keysize); // for example
    SecretKey secretKey = keyGen.generateKey();
    byte[] encoded = secretKey.getEncoded();
    return Base64.encodeToString(encoded, Base64.DEFAULT);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:8,代码来源:CryptHelper.java

示例14: getAESKey

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
private static SecretKey getAESKey(int bits) {
	try {
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		keyGen.init(bits);
		return keyGen.generateKey();
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:10,代码来源:JWTUtil.java

示例15: ReadWriteSkip

import javax.crypto.KeyGenerator; //导入方法依赖的package包/类
ReadWriteSkip(int keyLength, int textLength, int AADLength)
        throws Exception {
    this.keyLength = keyLength;
    this.textLength = textLength;

    // init AAD
    this.AAD = Helper.generateBytes(AADLength);

    // init a secret Key
    KeyGenerator kg = KeyGenerator.getInstance(AES, PROVIDER);
    kg.init(this.keyLength);
    this.key = kg.generateKey();

    this.plaintext = Helper.generateBytes(textLength);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ReadWriteSkip.java


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