package utils;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import javax.crypto.Cipher;
public class RsaTool {
//密钥对临时存储容器,正常情况应该持久化
private static KeyPair keyPair;
//相同的种子,生成的密钥对是不变的
private static String seed="37d5aed075525d4fa0fe635231cba447";
private static final String KEY_ALGORITHM = "RSA";
private static final String SIGNATURE_ALGORITHM = "MD5withRSA";
public static void signatureVeriry() {
try {
String publicKey = getPublicKey();
String privateKey = getPrivateKey();
OutputText.showMsg(publicKey, "publicKey");
OutputText.showMsg(privateKey, "privateKey");
String sign = generateSign(publicKey,privateKey);
boolean verifyRes = verifySign(publicKey,sign,publicKey);
String msg="pass";
if(!verifyRes) {
msg="fail";
}
OutputText.showMsg(sign, "sign");
O