/// <summary> /// /// </summary> /// <param name="pemString"></param> /// <param name="type"></param> /// <returns></returns> public static byte[] GetBytesFromPEM(string pemString) { PEMtypes keyType = getPEMType(pemString); Dictionary <string, string> extras; if (keyType == PEMtypes.unknown) { return(null); } return(GetBytesFromPEM(pemString, keyType, out extras)); }
public static string PEMheader(PEMtypes p) { if (p == PEMtypes.PEM_SSH2_PUBLIC) { return("---- BEGIN " + PEMs[p] + " ----"); } else { return("-----BEGIN " + PEMs[p] + "-----"); } }
public static string PEMfooter(PEMtypes p) { if (p == PEMtypes.PEM_SSH2_PUBLIC) { return("---- END " + PEMs[p] + " ----"); } else { return("-----END " + PEMs[p] + "-----"); } }
public static byte[] GetBytesFromPEM(string pemString) { Dictionary <string, string> dictionary; PEMtypes type = getPEMType(pemString); if (type == PEMtypes.unknown) { return(null); } return(GetBytesFromPEM(pemString, type, out dictionary)); }
public static string packagePEM(byte[] bytes, PEMtypes type) { TextWriter outputStream = new StringWriter(); outputStream.NewLine = "\n"; var base64 = Convert.ToBase64String(bytes, 0, (int)bytes.Length).ToCharArray(); outputStream.WriteLine(Helpers.PEMheader(type)); // Output as Base64 with lines chopped at 64 characters for (var i = 0; i < base64.Length; i += 64) { outputStream.WriteLine(base64, i, Math.Min(64, base64.Length - i)); } outputStream.WriteLine(Helpers.PEMfooter(type)); return(outputStream.ToString()); }
public static byte[] GetBytesFromPEM(string pemString, PEMtypes type, out Dictionary <string, string> extras) { extras = new Dictionary <string, string>(); string str3 = ""; string str = PEMheader(type); string str2 = PEMfooter(type); char[] separator = new char[] { '\n' }; foreach (string str4 in pemString.Replace("\r", "").Split(separator)) { if (str4.Contains(":")) { extras.Add(str4.Substring(0, str4.IndexOf(":") - 1), str4.Substring(str4.IndexOf(":") + 1)); } else if (str4 != "") { str3 = str3 + str4 + "\n"; } } int startIndex = str3.IndexOf(str) + str.Length; int length = str3.IndexOf(str2, startIndex) - startIndex; return(Convert.FromBase64String(str3.Substring(startIndex, length))); }
public static string packagePEM(byte[] bytes,PEMtypes type) { TextWriter outputStream = new StringWriter(); outputStream.NewLine = "\n"; var base64 = Convert.ToBase64String(bytes, 0, (int)bytes.Length).ToCharArray(); outputStream.WriteLine(Helpers.PEMheader(type)); // Output as Base64 with lines chopped at 64 characters for (var i = 0; i < base64.Length; i += 64) { outputStream.WriteLine(base64, i, Math.Min(64, base64.Length - i)); } outputStream.WriteLine(Helpers.PEMfooter(type)); return outputStream.ToString(); }
public static byte[] GetBytesFromPEM(string pemString, out Dictionary <string, string> extras) { PEMtypes type = getPEMType(pemString); return(GetBytesFromPEM(pemString, type, out extras)); }
public static byte[] GetBytesFromPEM(string pemString, PEMtypes type) { Dictionary <string, string> extras; return(GetBytesFromPEM(pemString, type, out extras)); }
public static string PEMheader(PEMtypes p) { if (p == PEMtypes.PEM_SSH2_PUBLIC) { return "---- BEGIN " + PEMs[p] + " ----"; } else { return "-----BEGIN " + PEMs[p] + "-----"; } }
public static string PEMfooter(PEMtypes p) { if (p == PEMtypes.PEM_SSH2_PUBLIC) { return "---- END " + PEMs[p] + " ----"; } else { return "-----END " + PEMs[p] + "-----"; } }
public static byte[] GetBytesFromPEM(string pemString, PEMtypes type,out Dictionary<string,string> extras) { extras = new Dictionary<string, string>(); string header; string footer; string data=""; header = PEMheader(type); footer = PEMfooter(type); foreach(string s in pemString.Replace("\r","").Split('\n')) { if (s.Contains(":")) { extras.Add(s.Substring(0, s.IndexOf(":") - 1), s.Substring(s.IndexOf(":") + 1)); } else { if (s !="") data += s + "\n"; } } int start = data.IndexOf(header) + header.Length; int end = data.IndexOf(footer, start) - start; return Convert.FromBase64String(data.Substring(start, end)); }
public static byte[] GetBytesFromPEM(string pemString, PEMtypes type) { Dictionary<string, string> extras; return GetBytesFromPEM(pemString, type, out extras); }