RSA Digital Signature Algorithm (Java edition)

Source: Internet
Author: User

Digital Signature Algorithm Java version or on the code bar

        public static final String sign_algorithms = "Sha1withrsa"; /** * RSA Signature * @param content pending Signature data * @param privatekey private key * @param input_charset encoded format * @return Signature value */Publi c static string sign (string content, String Privatekey, String input_charset) {try {byte[] de           Code =base64.getdecoder (). Decode (Privatekey);           Pkcs8encodedkeyspec priPKCS8 = new Pkcs8encodedkeyspec (decode);           Keyfactory keyf= keyfactory.getinstance ("RSA");           Privatekey prikey= keyf.generateprivate (priPKCS8);           Java.security.Signature Signature = java.security.Signature.getInstance (SIGN_ALGORITHMS);           Signature.initsign (Prikey);           Signature.update (Content.getbytes (Input_charset));               Byte[] signed = Signature.sign ();        Return Base64.getencoder (). encodetostring (Signed);        } catch (Exception e) {e.printstacktrace ();    } return null;         }

  

Call Mode:

String sign = sign ("Content", "Privatekey", "utf-8");

Over,tks.

RSA Digital Signature Algorithm (Java edition)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.