In the past two days, the company needs to use digital certificates to retrieve and paste the code N years ago.
Package COM. jinhill. util; import Java. io. *; import Java. security. *; import Java. security. cert. certificateexception; import Java. security. cert. certificatefactory; import Java. security. cert. x509certificate; import Java. util. properties; public class test {public static string getsubjectdn (byte [] Der) {string DN = ""; try {bytearrayinputstream bin = new bytearrayinputstream (DER); // bouncycastleprovider provide R = new bouncycastleprovider (); // certificatefactory cf = certificatefactory. getinstance ("X509", // provider); certificatefactory cf = certificatefactory. getinstance ("X.509", "Sun"); x509certificate Cert = (x509certificate) Cf. generatecertificate (BIN); DN = cert. getsubjectdn (). getname (); bin. close ();} catch (certificateexception e) {e. printstacktrace ();} catch (nosuchproviderexception e) {e. printstacktr ACE ();} catch (ioexception e) {e. printstacktrace ();} return DN;} public static string parsecertdn (string DN, string type) {type = type + "="; string [] split = DN. split (","); For (string X: Split) {If (X. contains (type) {x = x. trim (); Return X. substring (type. length () ;}} return NULL;}/*** @ Param ARGs */public static void main (string [] ARGs) {try {fileinputstream FCM = new fileinputstream ("D:/work/R Oochloroform/newcerts/reader01.cer "); int FLEN = FCM. available (); byte [] Buf = new byte [FLEN]; Sox. read (BUF, 0, FLEN); string DN = getsubjectdn (BUF); string Cn = parsecertdn (DN, "cn"); system. out. println (CN);} catch (exception ex) {system. out. println ("An error occurred while reading the Certificate file! ");}}}