[转]java生成3DES对称秘钥和RSA非对称秘钥

阅读更多
/*1、对称加密3DES秘钥生成*/
KeyGenerator kg = KeyGenerator.getInstance("DESede");
kg.init(112);//must be equal to 112 or 168
System.out.println("SecretKey:");
System.out.println(new BASE64Encoder().encode(kg.generateKey().getEncoded()));
 
/*2、非对称加密RSA公钥和私钥生成*/
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");  
keyGen.initialize(512);//RSA keys must be at least 512 bits long
KeyPair key = keyGen.generateKeyPair();
System.out.println("PublicKey:");
System.out.println(new BASE64Encoder().encode(key.getPublic().getEncoded()));
System.out.println("PrivateKey:");
System.out.println(new BASE64Encoder().encode(key.getPrivate().getEncoded()));


引用
引自: http://my.oschina.net/h2do/blog/370684

你可能感兴趣的:(3DES,RSA,加密,java)