當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。