java signature decryption_Java RSA encryption decryption signature verification_PPT3031’s blog
importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.ObjectInputStream;importjava.io.ObjectOutputStream;importjava.security.Key;importjava.security.KeyFactory;importjava.security.KeyPair;importjava.security.KeyPairGenerator importjava.security.PrivateKey;importjava.security.PublicKey;importjava.security.SecureRandom;importjava.security.Signature;importjava.security.spec.PKCS8EncodedKeySpec;importjava.security.spec.X509EncodedKeySpec;importjavax.crypto.Cipher;importun .misc .BASE64Decoder;importsun.misc.BASE64Encoder;/*** RSA encryption, supports fragment encryption * * BCD code (Binary-Coded Decimal) is also known as binary coded decimal or binary-decimal code. * Use 4-digit binary numbers to represent the 10 numbers from 0 to 9 in 1-digit decimal numbers. * is a binary form of number encoding, using binary coded decimal codes. * Note: Most of the BCD codes mentioned in daily life refer to the 8421BCD code format *@authorMing **/ public classRSAUtil {/**Specify the encryption algorithm as RSA*/ private static String ALGORITHM = “RSA”;/**Specify the size of the key*/ private static int KEYSIZE = 1024;/**Specify the public key storage file*/ private static String PUBLIC_KEY_FILE = “d:/PublicKey”;/**Specify the private key storage file*/ private static String PRIVATE_KEY_FILE = “d:/PrivateKey”; public static final String KEY_ALGORITHM = “RSA”;/**Customize a string*/ public static final String SIGNATURE_ALGORITHM = “shihaiming@#!RSA”;/*** generate key pair*/ public static void generateKeyPair() throwsException {if (getpublickey() == null || getprivatekey() == null) {/**RSA algorithm requires a trusted source of random numbers*/SecureRandom sr= newSecureRandom( );/**Create a KeyPairGenerator object for the RSA algorithm*/KeyPairGenerator kpg=KeyPairGenerator.getInstance(ALGORITHM);/**Use the above random data source to initialize the KeyPairGenerator object*/kpg.initialize(KEYSIZE, sr);/* *Generate key pair*/KeyPair kp=kpg.generateKeyPair();/**Get public key*/Key publicKey=kp.getPublic();/**Get private key*/Key privateKey=kp.getPrivate(); /**Write the generated key to…