/* * Copyright 2026 mingliqiye * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Base64NoPaddingCodec.kt * LastUpdate 2026-11-16 14:24:59 * UpdateUser MingLiPro */ package com.mingliqiye.utils.base import java.util.* /** * 无填充 Base64 URL 编解码器实现类。 * * 使用 URL 安全的 Base64 字母表,编码结果不带末尾的 '=' 填充字符。 */ internal class Base64NoPaddingCodec : BaseCodec { /** * Base64编码器实例 * 用于执行字节数组到Base64字符串的编码操作 */ val encoder: Base64.Encoder = Base64.getUrlEncoder().withoutPadding() /** * Base64解码器实例 * 用于执行Base64字符串到字节数组的解码操作 */ val decoder: Base64.Decoder = Base64.getUrlDecoder() /** * 将字节数组编码为Base64字符串 * * @param bytes 待编码的字节数组 * @return 编码后的Base64字符串 */ override fun encode(bytes: ByteArray): String { return encoder.encodeToString(bytes) } /** * 将Base64字符串解码为字节数组 * * @param string 待解码的Base64字符串 * @return 解码后的字节数组 */ override fun decode(string: String): ByteArray { return decoder.decode(string) } }