分对称的加密解密
package endual;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
public class SecretKeyTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
publicEnrypt() ;
privateDecrypt() ;
}
//共有加密
private static void publicEnrypt() throws Exception, Exception {
// TODO Auto-generated method stub
Cipher cipher = Cipher.getInstance("RSA") ; //非对称加密算法
Key arg1 = null;
KeyPairGenerator keyParGenerator = KeyPairGenerator.getInstance("RSA") ;
KeyPair keyPair = keyParGenerator.generateKeyPair() ;
PrivateKey pirvateKey = keyPair.getPrivate() ; //私有密匙
PublicKey publicKey = keyPair.getPublic() ; //共有密匙
cipher.init(Cipher.ENCRYPT_MODE, publicKey) ;
}
//私有解密
private static void privateDecrypt() {
// TODO Auto-generated method stub
}
}
主要是从解密加密的算法上去考虑的,还有就是key 产生 的类。百度下应该有详细的代码的