将用户输入的信息加密,解密

涉及的类:

1,javax.crypto.KeyGenerator:   public class KeyGenerator  extends Object  ,此类提供(对称)密钥生成器的功能。密钥生成器是使用此类的某个 getInstance 类方法构造的。

  第一步: 获取密匙生成器的具体方法:public static final KeyGenerator getInstance(String algorithm)  throws NoSuchAlgorithmException:为指定算法生成一个 KeyGenerator 对象。如果默认提供程序包提供所请求密钥生成器的实现,则返回包含该实现的 KeyGenerator 实例。如果默认提供程序包中不存在请求的密钥生成器,则搜索其他提供程序包。

参数:algorithm - 所请求的密钥算法的标准名称。

Algorithm Name Description
AES Key generator for use with the AES algorithm.
ARCFOUR Key generator for use with the ARCFOUR (RC4) algorithm.
Blowfish Key generator for use with the Blowfish algorithm.
DES Key generator for use with the DES algorithm.
DESede Key generator for use with the DESede (triple-DES) algorithm.
HmacMD5 Key generator for use with the HmacMD5 algorithm.
HmacSHA1
HmacSHA224
HmacSHA256
HmacSHA384
HmacSHA512
Keys generator for use with the various flavors of the HmacSHA algorithms.
RC2 Key generator for use with the RC2 algorithm.

第二步:初始化密匙生成器的长度:public final void init(int keysize) ,初始化此密钥生成器,使其具有确定的密钥长度

参数:keysize - 密钥长度。这是特定于算法的一种规格,是按位数指定的。

猜你喜欢

转载自www.cnblogs.com/lq13035130506/p/11727953.html