Base64

public class Base64 : @unchecked Sendable

Utility class for Base64 encoding and decoding. Provides methods to encode data to a Base64 string and decode a Base64 string back to data. Supports standard and URL-safe Base64 variants.

Public Methods

  • Checks if a string is Base64 encoded.

    Declaration

    Swift

    public static func isBase64Encoded(_ value: String) -> Bool

    Parameters

    value

    The string to check.

    Return Value

    true if the string is Base64 encoded, false otherwise.

  • Decodes a Base64 encoded string.

    Throws

    UriParseError.invalidBase64 if the string is not valid Base64.

    Declaration

    Swift

    public static func decodeBase64(_ value: String) throws -> String

    Parameters

    value

    The Base64 encoded string.

    Return Value

    The decoded string.

  • Decodes a Base64 URL encoded string.

    Throws

    UriParseError.invalidBase64 if the string is not valid Base64.

    Declaration

    Swift

    public static func decodeBase64Url(_ value: String) throws -> String

    Parameters

    value

    The Base64 URL encoded string.

    Return Value

    The decoded string.

  • Decodes a Base64 URL encoded string to Data.

    Declaration

    Swift

    public static func decodeBase64UrlToData(_ base64URLString: String) -> Data?

    Parameters

    base64URLString

    The Base64 URL encoded string.

    Return Value

    The decoded Data, or nil if decoding fails.

  • Encodes a string as Base64.

    Declaration

    Swift

    public static func encodeBase64(_ value: String) -> String

    Parameters

    value

    The string to encode.

    Return Value

    The Base64 encoded string.

  • Recodes a Base64 URL encoded value to a standard Base64 encoded value without URL-safe characters.

    Throws

    UriParseError.invalidBase64 if the string is not valid Base64.

    Declaration

    Swift

    public static func recodeBase64NoWrapUrlSafeValueToNoWrap(_ value: String) throws -> String

    Parameters

    value

    The Base64 URL encoded string.

    Return Value

    The recoded standard Base64 string.

  • Recodes a Base64 encoded value to a URL-safe Base64 encoding without padding.

    Throws

    UriParseError.invalidBase64 if the string is not valid Base64.

    Declaration

    Swift

    public static func recodeBase64NoWrapValueToUrlSafeNoWrap(_ value: String) throws -> String

    Parameters

    value

    The Base64 encoded string.

    Return Value

    The recoded URL-safe Base64 string.