Search in sources :

Example 91 with KeyGenerator

use of javax.crypto.KeyGenerator in project protools by SeanDragon.

the class ToolIDEA method initKey.

/**
 * 生成密钥 <br>
 *
 * @return byte[] 二进制密钥
 *
 * @throws Exception
 */
public static byte[] initKey() throws NoSuchAlgorithmException {
    // 实例化
    KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM);
    // 初始化
    kg.init(128);
    // 生成秘密密钥
    SecretKey secretKey = kg.generateKey();
    // 获得密钥的二进制编码形式
    return secretKey.getEncoded();
}
Also used : SecretKey(javax.crypto.SecretKey) KeyGenerator(javax.crypto.KeyGenerator)

Example 92 with KeyGenerator

use of javax.crypto.KeyGenerator in project protools by SeanDragon.

the class ToolHmacRipeMD method initHmacRipeMD160Key.

/**
 * 初始化HmacRipeMD160密钥
 *
 * @return byte[] 密钥
 *
 * @throws Exception
 */
public static byte[] initHmacRipeMD160Key() throws NoSuchAlgorithmException {
    // 加入BouncyCastleProvider支持
    Security.addProvider(new BouncyCastleProvider());
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacRipeMD160");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}
Also used : SecretKey(javax.crypto.SecretKey) KeyGenerator(javax.crypto.KeyGenerator) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 93 with KeyGenerator

use of javax.crypto.KeyGenerator in project protools by SeanDragon.

the class ToolAES method initKey.

/**
 * 生成密钥 <br>
 *
 * @return byte[] 二进制密钥
 *
 * @throws Exception
 */
public static byte[] initKey() throws NoSuchAlgorithmException {
    // 实例化
    KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM);
    /*
         * AES 要求密钥长度为 128位、192位或 256位
         */
    kg.init(256);
    // 生成秘密密钥
    SecretKey secretKey = kg.generateKey();
    // 获得密钥的二进制编码形式
    return secretKey.getEncoded();
}
Also used : SecretKey(javax.crypto.SecretKey) KeyGenerator(javax.crypto.KeyGenerator)

Example 94 with KeyGenerator

use of javax.crypto.KeyGenerator in project protools by SeanDragon.

the class ToolMAC method initHmacSHAKey.

/**
 * 初始化HmacSHA1密钥
 *
 * @return
 *
 * @throws Exception
 */
public static byte[] initHmacSHAKey() throws NoSuchAlgorithmException {
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HMacTiger");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}
Also used : SecretKey(javax.crypto.SecretKey) KeyGenerator(javax.crypto.KeyGenerator)

Example 95 with KeyGenerator

use of javax.crypto.KeyGenerator in project protools by SeanDragon.

the class ToolMAC_BCP method initHmacMD2Key.

/**
 * 初始化HmacMD2密钥
 *
 * @return byte[] 密钥
 *
 * @throws Exception
 */
public static byte[] initHmacMD2Key() throws NoSuchAlgorithmException {
    // 加入BouncyCastleProvider支持
    Security.addProvider(new BouncyCastleProvider());
    // 初始化KeyGenerator
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD2");
    // 产生秘密密钥
    SecretKey secretKey = keyGenerator.generateKey();
    // 获得密钥
    return secretKey.getEncoded();
}
Also used : SecretKey(javax.crypto.SecretKey) KeyGenerator(javax.crypto.KeyGenerator) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

KeyGenerator (javax.crypto.KeyGenerator)464 SecretKey (javax.crypto.SecretKey)343 Test (org.junit.Test)106 ArrayList (java.util.ArrayList)104 SecureRandom (java.security.SecureRandom)99 Document (org.w3c.dom.Document)98 InputStream (java.io.InputStream)95 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)93 ByteArrayOutputStream (java.io.ByteArrayOutputStream)87 NodeList (org.w3c.dom.NodeList)82 Cipher (javax.crypto.Cipher)79 ByteArrayInputStream (java.io.ByteArrayInputStream)75 XMLStreamReader (javax.xml.stream.XMLStreamReader)68 XMLSecurityProperties (org.apache.xml.security.stax.ext.XMLSecurityProperties)68 DocumentBuilder (javax.xml.parsers.DocumentBuilder)62 Key (java.security.Key)58 QName (javax.xml.namespace.QName)47 IOException (java.io.IOException)45 SecurePart (org.apache.xml.security.stax.ext.SecurePart)40 SecretKeySpec (javax.crypto.spec.SecretKeySpec)39