Records:
Public Abstract classRsacodersignature {Private Static FinalString Private_key = "Rsaprivate_key"; Private Static FinalString Public_key = "Rsapublic_key"; Private Static Final intKey_size = 512; Private Static FinalString key_algorithm = "RSA"; Private Static FinalString signature_algorithm = "Md5withrsa"; Public Static byte[] Getprivatekey (map<string, object> keyMap)throwsException {key key=(Key) keymap.get (Private_key); returnkey.getencoded (); } Public Static byte[] Getpublickey (map<string, object> keyMap)throwsException {key key=(Key) keymap.get (Public_key); returnkey.getencoded (); } /*** Production Public private key is saved to map *@return * @throwsException*/ Public StaticMap<string, object> Initkey ()throwsException {Map<string, object> KeyMap =NewHashmap<string, object> (2); Keypairgenerator Keypaigen=keypairgenerator.getinstance (Key_algorithm); Keypaigen.initialize (key_size); KeyPair pair=Keypaigen.generatekeypair (); Rsapublickey PublicKey=(Rsapublickey) pair.getpublic (); Rsaprivatekey Privatekey=(Rsaprivatekey) pair.getprivate (); Keymap.put (Public_key, PublicKey); Keymap.put (Private_key, Privatekey); returnKeyMap; } /*** Digital signature production with private key, *@paramData *@paramPrivatekey *@return * @throwsException*/ Public Static byte[] Sign (byte[] Data,byte[] privatekey)throwsException {pkcs8encodedkeyspec PKC=NewPkcs8encodedkeyspec (Privatekey); Keyfactory keyfactory=keyfactory.getinstance (Key_algorithm); Privatekey Prikey=keyfactory.generateprivate (PKC); Signature Sig=signature.getinstance (Signature_algorithm); Sig.initsign (Prikey); Sig.update (data); returnsig.sign (); } /*** Verify the correctness of the private key encryption with the public key decryption, *@paramData *@paramPublicKey *@paramSigns encryption digital certificate for private key production *@return * @throwsException*/ Public Static BooleanVerifybyte[] Data,byte[] PublicKey,byte[] signs)throwsException {x509encodedkeyspec PKC=NewX509encodedkeyspec (PublicKey); Keyfactory keyfactory=keyfactory.getinstance (Key_algorithm); PublicKey PubKey=keyfactory.generatepublic (PKC); Signature Sig=signature.getinstance (Signature_algorithm); Sig.initverify (PubKey); Sig.update (data); returnsig.verify (signs); }}
The classic digital Signature Algorithm-rsa