예제 #1
0
        /// <summary>
        /// Import certificate from string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static GXPkcs8 Import(string value)
        {
            GXPrivateKey pk;
            GXPkcs8      ret;

            try
            {
                ret = GXPkcs8.FromPem(value);
            }
            catch (Exception)
            {
                try
                {
                    ret = GXPkcs8.FromDer(value);
                }
                catch (Exception)
                {
                    try
                    {
                        //If PEM.
                        pk  = GXPrivateKey.FromPem(value);
                        ret = new GXPkcs8(pk);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            //If DER.
                            pk  = GXPrivateKey.FromDer(value);
                            ret = new GXPkcs8(pk);
                        }
                        catch (Exception)
                        {
                            try
                            {
                                //If Raw.
                                pk  = GXPrivateKey.FromRawBytes(GXDLMSTranslator.HexToBytes(value));
                                ret = new GXPkcs8(pk);
                            }
                            catch (Exception)
                            {
                                throw new Exception("Invalid private key format.");
                            }
                        }
                    }
                }
            }
            return(ret);
        }
예제 #2
0
 /// <summary>Load private key from the PEM file.
 /// </summary>
 /// <param name="path">File path. </param>
 /// <returns> Created GXPkcs8 object. </returns>
 public static GXPkcs8 Load(string path)
 {
     return(GXPkcs8.FromPem(File.ReadAllText(path)));
 }