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.
-
Checks if a string is Base64 encoded.
Declaration
Swift
public static func isBase64Encoded(_ value: String) -> BoolParameters
valueThe string to check.
Return Value
trueif the string is Base64 encoded,falseotherwise. -
Decodes a Base64 encoded string.
Throws
UriParseError.invalidBase64if the string is not valid Base64.Declaration
Swift
public static func decodeBase64(_ value: String) throws -> StringParameters
valueThe Base64 encoded string.
Return Value
The decoded string.
-
Decodes a Base64 URL encoded string.
Throws
UriParseError.invalidBase64if the string is not valid Base64.Declaration
Swift
public static func decodeBase64Url(_ value: String) throws -> StringParameters
valueThe 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
base64URLStringThe Base64 URL encoded string.
Return Value
The decoded Data, or
nilif decoding fails. -
Encodes a string as Base64.
Declaration
Swift
public static func encodeBase64(_ value: String) -> StringParameters
valueThe 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.invalidBase64if the string is not valid Base64.Declaration
Swift
public static func recodeBase64NoWrapUrlSafeValueToNoWrap(_ value: String) throws -> StringParameters
valueThe 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.invalidBase64if the string is not valid Base64.Declaration
Swift
public static func recodeBase64NoWrapValueToUrlSafeNoWrap(_ value: String) throws -> StringParameters
valueThe Base64 encoded string.
Return Value
The recoded URL-safe Base64 string.
View on GitHub