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