Convert Java-generated RSA public and private keys into. NET XML format used by

Source: Internet
Author: User
Tags modulus net xml

1  Private StaticString Getrsaprivatekeyasnetformat (byte[] encodedprivkey) {2         Try {3StringBuffer buff =NewStringBuffer (1024);4 5Pkcs8encodedkeyspec Pvkkeyspec =NewPkcs8encodedkeyspec (6 encodedprivkey);7Keyfactory keyfactory = keyfactory.getinstance ("RSA");8Rsaprivatecrtkey Pvkkey =(rsaprivatecrtkey) keyfactory9 . Generateprivate (PVKKEYSPEC);Ten  OneBuff.append ("<RSAKeyValue>"); ABuff.append ("<Modulus>" -+Codeutils.base64encode (Removemszero (Pvkkey.getmodulus () Tobytearray ())) -+ "</Modulus>"); the  -Buff.append ("<Exponent>" -+Codeutils.base64encode (Removemszero (pvkkey.getpublicexponent () -. Tobytearray ())) + "</Exponent>"); +  -Buff.append ("<P>" ++Codeutils.base64encode (Removemszero (PVKKEY.GETPRIMEP () Tobytearray ())) A+ "</P>"); at  -Buff.append ("<Q>" -+Codeutils.base64encode (Removemszero (Pvkkey.getprimeq () Tobytearray ())) -+ "</Q>"); -  -Buff.append ("<DP>" in+Codeutils.base64encode (Removemszero (PVKKEY.GETPRIMEEXPONENTP () -. Tobytearray ())) + "</DP>"); to  +Buff.append ("<DQ>" -+Codeutils.base64encode (Removemszero (PVKKEY.GETPRIMEEXPONENTQ () the. Tobytearray ())) + "</DQ>"); *  $Buff.append ("<InverseQ>"Panax Notoginseng+Codeutils.base64encode (Removemszero (pvkkey.getcrtcoefficient () -. Tobytearray ())) + "</InverseQ>"); the  +Buff.append ("<D>" A+Codeutils.base64encode (Removemszero (pvkkey.getprivateexponent () the. Tobytearray ())) + "</D>"); +Buff.append ("</RSAKeyValue>"); -  $             returnBuff.tostring (). ReplaceAll ("[\t\n\r]", ""); $}Catch(Exception e) { - System.err.println (e); -             return NULL; the         } -     }Wuyi  the     Private StaticString Getrsapublickeyasnetformat (byte[] encodedpublickey) { -         Try { Wu  -Keyfactory keyfactory = keyfactory.getinstance ("RSA"); AboutRsapublickey Pukkey = (rsapublickey) keyfactory.generatepublic (NewX509encodedkeyspec (Encodedpublickey)); $  -StringBuffer buff =NewStringBuffer (1024); -Buff.append ("<RSAKeyValue>"); -Buff.append ("<Modulus>" A+Codeutils.base64encode (Removemszero (Pukkey.getmodulus () Tobytearray ())) ++ "</Modulus>"); theBuff.append ("<Exponent>" -+ Codeutils.base64encode (Removemszero (Pukkey.getpublicexponent () Tobytearray ()) + "</Exponent>"); $Buff.append ("</RSAKeyValue>"); the             returnBuff.tostring (). ReplaceAll ("[\t\n\r]", ""); the}Catch(Exception e) { the System.err.println (e); the             return NULL; -         } in}

Convert Java-generated RSA public and private keys into. NET XML format used by

Related Article

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.