public static byte[] ExportSubjectPublicKeyInfo(this ECDsa ecdsa, AsnFormat format) { return(format switch { AsnFormat.Der => ecdsa.ExportSubjectPublicKeyInfo(), AsnFormat.Pem => PemFormater.ToPemBytes(ecdsa.ExportSubjectPublicKeyInfo(), "PUBLIC KEY"), _ => ThrowHelpers.NotImplemented <byte[]>(nameof(ECDsaExtensions)) });
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, " -----")); }
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)); }
public static bool TryFromOid(string hashAlgorithmOid, out HashAlgorithmName hashAlgorithmName) { ThrowHelpers.CheckNull(nameof(hashAlgorithmOid), hashAlgorithmOid); (bool success, HashAlgorithmName algorithm) = hashAlgorithmOid switch { Oids.MD5 => (true, HashAlgorithmName.MD5), Oids.SHA1 => (true, HashAlgorithmName.SHA1), Oids.SHA256 => (true, HashAlgorithmName.SHA256), Oids.SHA384 => (true, HashAlgorithmName.SHA384), Oids.SHA512 => (true, HashAlgorithmName.SHA512), _ => (false, default)
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)); } }
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))); } }
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); }); } }
public static byte[] GetBytes(string hexValue) { ThrowHelpers.CheckNull(nameof(hexValue), hexValue); return(GetBytes(hexValue.AsSpan())); }