Match the Certificate Export ( .pfx & .jks ) by C# & Java with Same Result.

Match the Certificate Export ( .pfx & .jks ) by C# & Java with Same Result.

 
   Usage :
 
   Certificate Export is to Perform the Key Sharing for SOAP Server & SOAP Client.
   There is no Restriction on Code Language ( .net or Java ) for Both Side ( SOAP Server or SOAP Client ).
 
   At the Beginning, SOAP Client Application would make a SOAP Request to SOAP Server.
   There is a Hash of Certificate Export Value from the SOAP Envelop Content or the SOAP Envelop Header.
   ( The Physical Certificate File has been distributed to SOAP Client before. )
   When SOAP Server receives this, it would validate the Hash Value which is corrected or not from the Code.
   If it is corrected,
   the SOAP Client would be classified as an Authorized SOAP Client and would return the requested value to SOAP Client.
   Otherwise, the Access Denied Object would be returned to SOAP Client.
 
   Java ( .jks )
 
   import java.io.FileInputStream;
   import java.security.KeyStore;
   import java.security.MessageDigest;
   import java.security.cert.Certificate;
 
   public static String loadKey(String keystorefilepath, String passwd, String alias, String instancetype) throws Exception
   {
 
      FileInputStream inputstream = new FileInputStream(keystorefilepath);
 
      KeyStore keystore = null;
      keystore = KeyStore.getInstance(instancetype);
      keystore.load(inputstream, passwd.toCharArray());
 
      Certificate cert = keystore.getCertificate(alias);
 
      byte[] certBuf = cert.getEncoded();
 
      return new sun.misc.BASE64Encoder().encode(certBuf);
 
   }
 
   C# ( .pfx )
 
   using System;
   using System.Text;
   using System.Security.Cryptography.X509Certificates;
 
   private string ExportToPEM(string filename, string password)
   {
      X509Certificate2 cert = new X509Certificate2(filename, password);
      return Convert.ToBase64String(cert.Export(X509ContentType.Cert), Base64FormattingOptions.InsertLineBreaks);
   }