Esempio n. 1
0
        public static string ToPem(ReadOnlySpan <byte> data, string name)
        {
            ThrowHelpers.CheckNullOrEempty(nameof(name), name);

            return(string.Concat("-----BEGIN ", name, "-----\r\n",
                                 Convert.ToBase64String(data, Base64FormattingOptions.InsertLineBreaks),
                                 "\r\n-----END ", name, " -----"));
        }
Esempio n. 2
0
        public static byte[] ToPemBytes(ReadOnlySpan <byte> data, string name)
        {
            ThrowHelpers.CheckNullOrEempty(nameof(name), name);

            string pem = string.Concat("-----BEGIN ", name, "-----\r\n",
                                       Convert.ToBase64String(data, Base64FormattingOptions.InsertLineBreaks),
                                       "\r\n-----END ", name, " -----");

            return(Encoding.ASCII.GetBytes(pem));
        }
Esempio n. 3
0
        public static TResult ExecuteWithSecureString <TResult, TContext>(SecureString secureString, Encoding encoding, TContext context, Func <byte[], TContext, TResult> action)
        {
            ThrowHelpers.CheckNull(nameof(encoding), encoding);
            ThrowHelpers.CheckNull(nameof(action), action);

            if (secureString == null)
            {
                return(action.Invoke(null, context));
            }
            else
            {
                return(ExecuteWithSecureStringInternal <TResult, TContext>(secureString, encoding, context, action));
            }
        }
Esempio n. 4
0
        public static TResult ExecuteWithSecureString <TResult>(SecureString secureString, Encoding encoding, Func <byte[], TResult> action)
        {
            ThrowHelpers.CheckNull(nameof(encoding), encoding);
            ThrowHelpers.CheckNull(nameof(action), action);

            if (secureString == null)
            {
                return(action.Invoke(null));
            }
            else
            {
                return(ExecuteWithSecureStringInternal <TResult, int>(secureString, encoding, 0, (buffer, ctx) => action(buffer)));
            }
        }
Esempio n. 5
0
        public static void ExecuteWithSecureString(SecureString secureString, Encoding encoding, Action <byte[]> action)
        {
            ThrowHelpers.CheckNull(nameof(encoding), encoding);
            ThrowHelpers.CheckNull(nameof(action), action);

            if (secureString == null)
            {
                action.Invoke(null);
            }
            else
            {
                ExecuteWithSecureStringInternal <int, int>(secureString, encoding, 0, (buffer, ctx) =>
                {
                    action.Invoke(buffer);
                    return(0);
                });
            }
        }
Esempio n. 6
0
 public static byte[] GetBytes(string hexValue)
 {
     ThrowHelpers.CheckNull(nameof(hexValue), hexValue);
     return(GetBytes(hexValue.AsSpan()));
 }