/encrypt 添加 base64 对 base64url 格式的支持

This commit is contained in:
A.C.Sukazyo Eyre 2022-10-18 16:26:36 +08:00
parent 5bb19095c8
commit 58b6f863bd
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
3 changed files with 11 additions and 7 deletions

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.8.0.8 VERSION = 0.8.0.9
CODENAME = putian CODENAME = putian

View File

@ -4,7 +4,7 @@ package cc.sukazyo.cono.morny;
* the final field that will be updated by gradle automatically. * the final field that will be updated by gradle automatically.
*/ */
public class GradleProjectConfigures { public class GradleProjectConfigures {
public static final String VERSION = "0.8.0.8"; public static final String VERSION = "0.8.0.9";
public static final String CODENAME = "putian"; public static final String CODENAME = "putian";
public static final long COMPILE_TIMESTAMP = 1665999835121L; public static final long COMPILE_TIMESTAMP = 1666081545158L;
} }

View File

@ -39,7 +39,9 @@ public class Encryptor implements ITelegramCommand {
MornyCoeur.extra().exec(new SendMessage( MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(), """ event.message().chat().id(), """
<b><u>base64</u></b>, b64 <b><u>base64</u></b>, b64
<b><u>base64url</u></b>, base64u, b64u
<b><u>base64decode</u></b>, base64d, b64d <b><u>base64decode</u></b>, base64d, b64d
<b><u>base64url-decode</u></b>, base64ud, b64ud
<b><u>sha1</u></b> <b><u>sha1</u></b>
<b><u>sha256</u></b> <b><u>sha256</u></b>
<b><u>sha512</u></b> <b><u>sha512</u></b>
@ -132,8 +134,9 @@ public class Encryptor implements ITelegramCommand {
byte[] result = null; byte[] result = null;
String resultName = null; String resultName = null;
switch (command.getArgs()[0]) { switch (command.getArgs()[0]) {
case "base64", "b64" -> { case "base64", "b64", "base64url", "base64u", "b64u" -> {
result = Base64.getEncoder().encode(data); final Base64.Encoder b64tool = command.getArgs()[0].contains("u") ? Base64.getUrlEncoder() : Base64.getEncoder();
result = b64tool.encode(data);
if (!inputText) { if (!inputText) {
echoString = false; echoString = false;
resultName = dataName+".b64.txt"; resultName = dataName+".b64.txt";
@ -141,8 +144,9 @@ public class Encryptor implements ITelegramCommand {
resultString = new String(result, CommonEncrypt.ENCRYPT_STANDARD_CHARSET); resultString = new String(result, CommonEncrypt.ENCRYPT_STANDARD_CHARSET);
} }
} }
case "base64decode", "base64d", "b64d" -> { case "base64decode", "base64d", "b64d", "base64url-decode", "base64ud", "b64ud" -> {
try { result = Base64.getDecoder().decode(data); } final Base64.Decoder b64tool = command.getArgs()[0].contains("u") ? Base64.getUrlDecoder() : Base64.getDecoder();
try { result = b64tool.decode(data); }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
MornyCoeur.extra().exec(new SendSticker( MornyCoeur.extra().exec(new SendSticker(
event.message().chat().id(), TelegramStickers.ID_404 event.message().chat().id(), TelegramStickers.ID_404