<address id="zhpbl"></address>
<noframes id="zhpbl">
<address id="zhpbl"><form id="zhpbl"><th id="zhpbl"></th></form></address>

    <em id="zhpbl"></em>

      <address id="zhpbl"><th id="zhpbl"><progress id="zhpbl"></progress></th></address>
      更多精彩內容,歡迎關注:

      視頻號
      視頻號

      抖音
      抖音

      快手
      快手

      微博
      微博

      java rsa公鑰加密

      文檔

      java rsa公鑰加密

      javarsa公鑰加密是一種加密技術。一般采用的公鑰加密算法有:1、RSA加密算法:以數論的歐拉定理為基礎,是第一個兼有安全性與實用性的公鑰加密算法,已經變成國際標準。2、 ELGAMAL加密算法:在有限域上離散對數的基礎上的公鑰加密體制,它的作用是加密,也有數字簽名的功能。
      推薦度:
      導讀javarsa公鑰加密是一種加密技術。一般采用的公鑰加密算法有:1、RSA加密算法:以數論的歐拉定理為基礎,是第一個兼有安全性與實用性的公鑰加密算法,已經變成國際標準。2、 ELGAMAL加密算法:在有限域上離散對數的基礎上的公鑰加密體制,它的作用是加密,也有數字簽名的功能。

      ? ?

      java rsa公鑰加密是什么?讓我們一起來了解一下吧!

      java rsa公鑰加密是一種加密技術。秘鑰是指數字或者字符串,在加/解密的時候傳遞加/解密算法。公鑰的密碼體制有三個內容,分別是公鑰、私鑰與加/解密算法。

      一般我們采用的公鑰加密算法有以下幾種:

      1.?RSA加密算法:以數論的歐拉定理為基礎,是第一個兼有安全性與實用性的公鑰加密算法,已經變成了國際標準。

      2.?ELGAMAL加密算法:在有限域上離散對數的基礎上的公鑰加密體制,它的作用是加密,也有數字簽名的功能。

      實戰演練,具體步驟如下:

      public?class?KeyGenerater?{undefined
      ?
      private?byte[]?priKey;
      ?
      private?byte[]?pubKey;
      ?
      public?void?generater()?{undefined
      ?
      try?{undefined
      ?
      java.security.KeyPairGenerator?keygen?=?java.security.KeyPairGenerator
      ?
      .getInstance("RSA");
      ?
      SecureRandom?secrand?=?new?SecureRandom();
      ?
      secrand.setSeed("syj".getBytes());?//?初始化隨機產生器
      ?
      keygen.initialize(1024,?secrand);
      ?
      KeyPair?keys?=?keygen.genKeyPair();
      ?
      PublicKey?pubkey?=?keys.getPublic();
      ?
      PrivateKey?prikey?=?keys.getPrivate();
      ?
      pubKey?=?Base64.encodeToByte(pubkey.getEncoded());
      ?
      priKey?=?Base64.encodeToByte(prikey.getEncoded());
      ?
      System.out.println("pubKey?=?"?+?new?String(pubKey));
      ?
      System.out.println("priKey?=?"?+?new?String(priKey));
      ?
      }?catch?(java.lang.Exception?e)?{undefined
      ?
      System.out.println("生成密鑰對失敗");
      ?
      e.printStackTrace();
      ?
      }
      ?
      }
      ?
      public?byte[]?getPriKey()?{undefined
      ?
      return?priKey;
      ?
      }
      ?
      public?byte[]?getPubKey()?{undefined
      ?
      return?pubKey;
      ?
      }
      ?
      }
      ?
      public?class?Signaturer?{undefined
      ?
      /**
      ?
      *
      ?
      *?Description:數字簽名
      ?
      *
      ?
      */
      ?
      public?static?byte[]?sign(byte[]?priKeyText,?String?plainText)?{undefined
      ?
      try?{undefined
      ?
      PKCS8EncodedKeySpec?priPKCS8?=?new?PKCS8EncodedKeySpec(Base64
      ?
      .decode(priKeyText));
      ?
      KeyFactory?keyf?=?KeyFactory.getInstance("RSA");
      ?
      PrivateKey?prikey?=?keyf.generatePrivate(priPKCS8);
      ?
      //?用私鑰對信息生成數字簽名
      ?
      java.security.Signature?signet?=?java.security.Signature
      ?
      .getInstance("MD5withRSA");
      ?
      signet.initSign(prikey);
      ?
      signet.update(plainText.getBytes());
      ?
      byte[]?signed?=?Base64.encodeToByte(signet.sign());
      ?
      return?signed;
      ?
      }?catch?(java.lang.Exception?e)?{undefined
      ?
      System.out.println("簽名失敗");
      ?
      e.printStackTrace();
      ?
      }
      ?
      return?null;
      ?
      }
      ?
      }
      ?
      public?class?SignProvider?{undefined
      ?
      private?SignProvider()?{undefined
      ?
      }
      ?
      /**
      ?
      *
      ?
      *?Description:校驗數字簽名,此方法不會拋出任務異常,成功返回true,失敗返回false,要求全部參數不能為空
      ?
      *
      ?
      *?@param?pubKeyText
      ?
      *????????????公鑰,base64編碼
      ?
      *?@param?plainText
      ?
      *????????????明文
      ?
      *?@param?signTest
      ?
      *????????????數字簽名的密文,base64編碼
      ?
      *?@return?校驗成功返回true?失敗返回false
      ?
      */
      ?
      public?static?boolean?verify(byte[]?pubKeyText,?String?plainText,
      ?
      byte[]?signText)?{undefined
      ?
      try?{undefined
      ?
      //?解密由base64編碼的公鑰,并構造X509EncodedKeySpec對象
      ?
      java.security.spec.X509EncodedKeySpec?bobPubKeySpec?=?new?java.security.spec.X509EncodedKeySpec(
      ?
      Base64.decode(pubKeyText));
      ?
      //?RSA對稱加密算法
      ?
      java.security.KeyFactory?keyFactory?=?java.security.KeyFactory
      ?
      .getInstance("RSA");
      ?
      //?取公鑰匙對象
      ?
      java.security.PublicKey?pubKey?=?keyFactory
      ?
      .generatePublic(bobPubKeySpec);
      ?
      //?解密由base64編碼的數字簽名
      ?
      byte[]?signed?=?Base64.decode(signText);
      ?
      java.security.Signature?signatureChecker?=?java.security.Signature
      ?
      .getInstance("MD5withRSA");
      ?
      signatureChecker.initVerify(pubKey);
      ?
      signatureChecker.update(plainText.getBytes());
      ?
      //?驗證簽名是否正常
      ?
      if?(signatureChecker.verify(signed))
      ?
      return?true;
      ?
      else
      ?
      return?false;
      ?
      }?catch?(Throwable?e)?{undefined
      ?
      System.out.println("校驗簽名失敗");
      ?
      e.printStackTrace();
      ?
      return?false;
      ?
      }
      ?
      }
      ?
      }

      以上就是小編今天的分享了,希望可以幫助到大家。

      文檔

      java rsa公鑰加密

      javarsa公鑰加密是一種加密技術。一般采用的公鑰加密算法有:1、RSA加密算法:以數論的歐拉定理為基礎,是第一個兼有安全性與實用性的公鑰加密算法,已經變成國際標準。2、 ELGAMAL加密算法:在有限域上離散對數的基礎上的公鑰加密體制,它的作用是加密,也有數字簽名的功能。
      推薦度:
      為你推薦
      資訊專欄
      熱門視頻
      相關推薦
      java rsa私鑰加密 java rtp java runnable java runtime.exec java rxjava java sandbox java script java selector java selenium java semaphore java separator java sequence java serializable java serializable接口 java serialversionuid java setlayout java platform java settimeout java plug-in java sftp java pipeline java ping java phoenix java paypal java path java rsa加密 java rotate java reverse java reverse() java retrofit java resume java resultset java result java rest java requests java partial java request java parser java repeat java parse
      Top 少妇高潮太爽了在线视频