RSA encrypted Java test code

xiaoxiao2021-03-06  72

/ ************************************************** *************************************** * $ Header $ * $ Revision $ * $ DATE $ * ====== ============================================================================================================================================================================================================= ===================================================================================================================================================================================15 *********************************************************** ************************ / Import Java.math.biginteger;

/ ** * TODO fill in the class information * * @Author yanfei * // * * Modify history * $ log $ * / public class rsaalgorithm {Biginteger MODULUS; BIGINTEGER PUBEY; Biginteger PrivateKey;

public RsaAlgorithm () {// generation prime number by RSATool // firstPrime = 8531092198849658733790731600554882570012152789399913498991432728465552799732061900314704077553345030066920054082501510392030827356194179550613533833120011 // secondPrime = 11924164233834228789553347947559934849185846410886263275018134490056496194726414252409563040573266992224048791555973043496961395481558244111428543221720059 modulus = new BigInteger ( "101726144473065307136337870615470919343156117442809797759084430536209670790991552510812754477461878742757991641136682979130702060350988957821490188383976777417165191105548667246571012637458521780431579809518401391017216215682790968984090555280612303529196758248073861960100967926654874945078177551837993000649"); publicKey = new BigInteger ( "777777771"); // privateKey = (X (firstPrime -1) (SecondPrime-1) 1) / publickey x is an integer. Privatekey = new Biginteger ("90174759107251056922810500448184537736176114745350210515099709 962555046427810408233459605518228418589756487520725572479732405052968217872244415294457554090608096384694464961513226211645941929392277330122178360116753803241577778113257146900485635077056441559542883250804009040964580876711072978171708583360391 ");} public String encrypt (String str) {BigInteger t = new BigInteger (str); t = t.modPow (publicKey, modulus); System.out.println (" encrypt str is: " t.toString ( )); Return tostrange ();

Public String Decrypt (String Str) {Biginteger C = New Biginteger (STR); C = C.Modpow (PrivateKey, MODULUS); System.out.Println ("Decrypt Str IS:" C.Tostring ()); Return C .tostring ();} public static void main (String [] args) {RSAALGORITHM RSA = new rsaalgorithm (); string encryptstr = RSA.Encrypt ("1234343"); RSA.Decrypt (EncryptStr.tostring ());}}

转载请注明原文地址:https://www.9cbs.com/read-91627.html

New Post(0)