[API Proposal]: String-to-String Base64 Encode/Decode

オープン
#136,711 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
api

調査の方向性

Start by reviewing the proposed APIs for System.Convert, System.Buffers.Text.Base64, and Base64Url, along with the existing Base64 APIs they extend. The issue does not name files or tests; the first step is to determine whether the proposed signatures and behavior fit the project’s API conventions. Done means the proposal has a clear design decision, including the Encoding parameters.

索引モデルが issue の本文から書いたものです。

説明

api-suggestion area-System.Runtime untriaged

Background and Motivation

Today, .NET's Base64 APIs have a gap: there is no direct way to encode a string to a Base64 string, or decode a Base64 string back to a string. Every existing method either accepts byte[] / ReadOnlySpan<byte> as input (encode side) or returns byte[] (decode side).

This pattern is extremely common across the .NET ecosystem. It appears in CI/CD tooling, configuration loaders, certificate handling, token encoding, and countless other packages. In many cases the Base64-encoded values are stored as strings in configuration files, databases, or API responses and need to be decoded back to strings when consumed later.

var certPem = Encoding.UTF8.GetString(Convert.FromBase64String(configuration.ClientCertificateData));

var releaseBuildBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(releaseBuild));

This is verbose, does not have easy discoverability and allocates an intermediate byte[] that could be avoided internally.

Proposed API

All methods accept ReadOnlySpan<char> rather than string — callers can pass a string directly thanks to the implicit conversion.

namespace System;

public static partial class Convert
{
    public static string ToBase64String(ReadOnlySpan<char> source, Encoding encoding);

    public static string ToBase64String(ReadOnlySpan<char> source, Encoding encoding, Base64FormattingOptions options);
}

namespace System.Buffers.Text;

public static partial class Base64
{
    public static string EncodeToString(ReadOnlySpan<char> source, Encoding encoding);

    public static string DecodeToString(ReadOnlySpan<char> source, Encoding encoding);
}

public static partial class Base64Url
{
    public static string EncodeToString(ReadOnlySpan<char> source, Encoding encoding);

    public static string DecodeToString(ReadOnlySpan<char> source, Encoding encoding);
}

API Usage

// Encode a connection string for safe storage in a config file
string encoded = Convert.ToBase64String("Server=prod;Database=App;User=admin;", Encoding.UTF8);

// Decode it back when reading the config
string connectionString = Convert.FromBase64ToString(encoded, Encoding.UTF8);

Edit: Added Encoding parameters

主要言語
C#
スター
18.4k
フォーク
5.8k
平均マージ
2日 13時間
マージ済み PR(30日)
588

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/runtime のほかの issue

dotnet/runtime の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。