Customer interface is the use of Java implementation, verify the use of Md5withrsa, open to see all understand, put on a piece on the Meng, beg to explain!!!!
Attached Java implementation method:
Package Main;import Java.security.keyfactory;import Java.security.keypair;import Java.security.nosuchalgorithmexception;import Java.security.privatekey;import Java.security.PublicKey;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.security.securerandom;public class Main {/** * Generate secret Key */ public static void Makekey () {String key_algorithm = "RSA"; Java.security.KeyPairGenerator keygen; try {keygen = java.security.KeyPairGenerator. getinstance (Key_algorithm); SecureRandom Secrand = new SecureRandom (); Secrand.setseed ("Tmripayment". GetBytes ()); Initialize the random generator keygen.initialize (1024); KeyPair keys = Keygen.genkeypair (); Rsapublickey PubKey = (rsapublickey) keys.getpublic (); RsaprivaTekey Prikey = (rsaprivatekey) keys.getprivate (); String pubkeystr= base64util.encodebase64 (pubkey.getencoded ());//Get the public key and do base64 encode string prikeystr= base64util . EncodeBase64 (prikey.getencoded ());//Get the private key and do base64 encode System.out.println ("Public key:" + pubkeystr); SYSTEM.OUT.PRINTLN ("Private key:" + prikeystr); } catch (NoSuchAlgorithmException e) {//TODO auto-generated catch block E.printstacktrace (); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }}/** * encryption * @return */public static String Encodedata () {try { byte[] data = "FDFDFSDFDFD". GetBytes (); String Privatekey = "MIICXAIBAAKBGQDOF3DZQPPVIVHRX2QWSZCV9CW5XHCEYURTY+HDPD684NSGGGNL" + "34clc1bcejlt3v 9h81sigvsudb++ybmczorrft+mat22yi98bcrp60vgvixftcci "+" Lc39b6g6i6ac5bufokwdukNunclvcojshmtgezceygocmzioiwxidbxerqidaqab "+" AOGANLYCROVUQM9J7V6YFUN/CAGNRI4WV0ZHEFUSPRQUHHBVVTVBUSPIB E3j4to5 "+" yxtn86ws0n0mljkqiobwfwvjodadneewfxui5ykyenpnvvzwto1jjrdy8qjpge94 "+" YNEBF glkyztic/zlq9sfboyqnctn2hu7isg2g4sge9bfcsucqqdnrc6yxg6jmfc/"+" 7hfqxj5ntqc72vybijf32yg8w1d1j3ghzzwtukia 8G3WMXFRYW9DFMZTDI3/MPSD "+" 1A9OG89DAKEA47OFZJ6XF7GZDBHDDKX/S9EHJQJP2Q6V7SYXNHDEWIOXJJPJ9QRP "+ "SKQG8A9M4NUL2FXJ2SPXAPOTHOKHQTGFTWJBAIKCOHGJBQMNQVL0MGK7L9/HXVCD" + "O72/okrlecfbu1449h2/zvi Jkb/mvs4jtyt31km8sipozoa4ftzs/epalyucqdhj "+" ly2hjfbzblparpxes5g8y8potoiupu/t2vyrskdq4ohxbja8ap7ipcj5rs Uzadaf "+" UYWYDZVHTLYRUBBR/2CCQGBBIWDLPTZHZI7QUMTABHQ9M5ZUGVTXDKSNOLTCEDSX "+" ABOGSB Prcpcgfffmy+fd/kdmeambyn+270dnhpvqlju= "; Byte[] keybytes; Keybytes = Base64util.decodebase64 (Privatekey); Pkcs8enCodedkeyspec Pkcs8keyspec = new Pkcs8encodedkeyspec (keybytes); Keyfactory keyfactory = keyfactory.getinstance ("RSA"); Privatekey Prikey = keyfactory.generateprivate (Pkcs8keyspec); Signature Signature = signature.getinstance ("Md5withrsa"); Signature.initsign (Prikey); Signature.update (data);//data is the source data byte array to generate the signature return base64util.encodebase64 (Base64util.encodebase64 (signature.si GN ()). GetBytes ()); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }//the private key to do base64 decoding return ""; }/** * Decryption * @return * * public static Boolean Decodedata (String msg) {string Publicke y = " Migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqdmrfaecg5zyhjks269vmywomywkwgfbbk31k44g0zlg8yn4c9joh4hyaykhn5mwy69q8sb82oalxbxmy1zq Shkk6kzzgorydqot/bvvg6kpdf9igtwky4yacvsr2c0zycviz+phxjrbteyvvlmbaxsr2lejambodcfm1ue9hj83qidaqab "; Try {byte[] data = "FDFDFSDFDFD". GetBytes (); byte[] PublicKey1 = base64util.decodebase64 (PublicKey);//Base64 decoding of the provided public key byte[] Sign = Base64util.decodebas E64 (New String (Base64util.decodebase64 (msg)));//signature needs to be done two times base64 decoding x509encodedkeyspec KeySpec = new X509encod Edkeyspec (PublicKey1); Keyfactory keyfactory = keyfactory.getinstance ("RSA"); PublicKey PubKey = Keyfactory.generatepublic (KeySpec); Signature Signature = signature.getinstance ("Md5withrsa"); Signature.initverify (PubKey); Signature.update (data); return signature.verify (sign); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }//the private key to do Base64 decoding return false; } public static void Main (string[] args) throws Exception {//TODO auto-generated method Stub// Makekey (); String msg = Encodedata (); SYSTEM.OUT.PRINTLN (msg); String msg = "ZLBGVNVXQM1YVJHHWDHGBVVYV24RAEJZRVB1WFAYCUHKDVIWBGL3AZY5T2VKWHBKMDLPL1U5AGYWCEVVK1H0M0RNMFNSRTNQM 1pyazfyt25xblzwtstrzmjhvgvpuxbsz0ozzvfkemfnawt5dznvuxrnzc81rgq4rglsr3pqumrhofd2oct1ekriakzbdwtqegg3y1pltedtt2ppq08rcfvqou qxzxh6zg1vpq== "; Boolean data = Decodedata (msg); SYSTEM.OUT.PRINTLN (data); }}
Reply content:
Customer interface is the use of Java implementation, verify the use of Md5withrsa, open to see all understand, put on a piece on the Meng, beg to explain!!!! Attached Java implementation method:
Package Main;import Java.security.keyfactory;import Java.security.keypair;import Java.security.nosuchalgorithmexception;import Java.security.privatekey;import Java.security.PublicKey;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.security.securerandom;public class Main {/** * Generate secret Key */ public static void Makekey () {String key_algorithm = "RSA"; Java.security.KeyPairGenerator keygen; try {keygen = java.security.KeyPairGenerator. getinstance (Key_algorithm); SecureRandom Secrand = new SecureRandom (); Secrand.setseed ("Tmripayment". GetBytes ()); Initialize the random generator keygen.initialize (1024); KeyPair keys = Keygen.genkeypair (); Rsapublickey PubKey = (rsapublickey) keys.getpublic (); RsaprivaTekey Prikey = (rsaprivatekey) keys.getprivate (); String pubkeystr= base64util.encodebase64 (pubkey.getencoded ());//Get the public key and do base64 encode string prikeystr= base64util . EncodeBase64 (prikey.getencoded ());//Get the private key and do base64 encode System.out.println ("Public key:" + pubkeystr); SYSTEM.OUT.PRINTLN ("Private key:" + prikeystr); } catch (NoSuchAlgorithmException e) {//TODO auto-generated catch block E.printstacktrace (); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }}/** * encryption * @return */public static String Encodedata () {try { byte[] data = "FDFDFSDFDFD". GetBytes (); String Privatekey = "MIICXAIBAAKBGQDOF3DZQPPVIVHRX2QWSZCV9CW5XHCEYURTY+HDPD684NSGGGNL" + "34clc1bcejlt3v 9h81sigvsudb++ybmczorrft+mat22yi98bcrp60vgvixftcci "+" Lc39b6g6i6ac5bufokwdukNunclvcojshmtgezceygocmzioiwxidbxerqidaqab "+" AOGANLYCROVUQM9J7V6YFUN/CAGNRI4WV0ZHEFUSPRQUHHBVVTVBUSPIB E3j4to5 "+" yxtn86ws0n0mljkqiobwfwvjodadneewfxui5ykyenpnvvzwto1jjrdy8qjpge94 "+" YNEBF glkyztic/zlq9sfboyqnctn2hu7isg2g4sge9bfcsucqqdnrc6yxg6jmfc/"+" 7hfqxj5ntqc72vybijf32yg8w1d1j3ghzzwtukia 8G3WMXFRYW9DFMZTDI3/MPSD "+" 1A9OG89DAKEA47OFZJ6XF7GZDBHDDKX/S9EHJQJP2Q6V7SYXNHDEWIOXJJPJ9QRP "+ "SKQG8A9M4NUL2FXJ2SPXAPOTHOKHQTGFTWJBAIKCOHGJBQMNQVL0MGK7L9/HXVCD" + "O72/okrlecfbu1449h2/zvi Jkb/mvs4jtyt31km8sipozoa4ftzs/epalyucqdhj "+" ly2hjfbzblparpxes5g8y8potoiupu/t2vyrskdq4ohxbja8ap7ipcj5rs Uzadaf "+" UYWYDZVHTLYRUBBR/2CCQGBBIWDLPTZHZI7QUMTABHQ9M5ZUGVTXDKSNOLTCEDSX "+" ABOGSB Prcpcgfffmy+fd/kdmeambyn+270dnhpvqlju= "; Byte[] keybytes; Keybytes = Base64util.decodebase64 (Privatekey); Pkcs8enCodedkeyspec Pkcs8keyspec = new Pkcs8encodedkeyspec (keybytes); Keyfactory keyfactory = keyfactory.getinstance ("RSA"); Privatekey Prikey = keyfactory.generateprivate (Pkcs8keyspec); Signature Signature = signature.getinstance ("Md5withrsa"); Signature.initsign (Prikey); Signature.update (data);//data is the source data byte array to generate the signature return base64util.encodebase64 (Base64util.encodebase64 (signature.si GN ()). GetBytes ()); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }//the private key to do base64 decoding return ""; }/** * Decryption * @return * * public static Boolean Decodedata (String msg) {string Publicke y = " Migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqdmrfaecg5zyhjks269vmywomywkwgfbbk31k44g0zlg8yn4c9joh4hyaykhn5mwy69q8sb82oalxbxmy1zq Shkk6kzzgorydqot/bvvg6kpdf9igtwky4yacvsr2c0zycviz+phxjrbteyvvlmbaxsr2lejambodcfm1ue9hj83qidaqab "; Try {byte[] data = "FDFDFSDFDFD". GetBytes (); byte[] PublicKey1 = base64util.decodebase64 (PublicKey);//Base64 decoding of the provided public key byte[] Sign = Base64util.decodebas E64 (New String (Base64util.decodebase64 (msg)));//signature needs to be done two times base64 decoding x509encodedkeyspec KeySpec = new X509encod Edkeyspec (PublicKey1); Keyfactory keyfactory = keyfactory.getinstance ("RSA"); PublicKey PubKey = Keyfactory.generatepublic (KeySpec); Signature Signature = signature.getinstance ("Md5withrsa"); Signature.initverify (PubKey); Signature.update (data); return signature.verify (sign); } catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); }//the private key to do Base64 decoding return false; } public static void Main (string[] args) throws Exception {//TODO auto-generated method Stub// Makekey (); String msg = Encodedata (); SYSTEM.OUT.PRINTLN (msg); String msg = "ZLBGVNVXQM1YVJHHWDHGBVVYV24RAEJZRVB1WFAYCUHKDVIWBGL3AZY5T2VKWHBKMDLPL1U5AGYWCEVVK1H0M0RNMFNSRTNQM 1pyazfyt25xblzwtstrzmjhvgvpuxbsz0ozzvfkemfnawt5dznvuxrnzc81rgq4rglsr3pqumrhofd2oct1ekriakzbdwtqegg3y1pltedtt2ppq08rcfvqou qxzxh6zg1vpq== "; Boolean data = Decodedata (msg); SYSTEM.OUT.PRINTLN (data); }}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.