Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -80,6 +80,22 @@ public final class AesUtil {
|
|||||||
private AesUtil() {
|
private AesUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts the specified data using the AES algorithm with the provided secret key.
|
||||||
|
*
|
||||||
|
* @param data the data to be encrypted
|
||||||
|
* @param secret the secret key used for encryption
|
||||||
|
* @param ivParam the iv param
|
||||||
|
* @return the encrypted data as a byte array
|
||||||
|
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
||||||
|
*/
|
||||||
|
public static byte[] encrypt(byte[] data, byte[] secret, byte[] ivParam) throws GeneralSecurityException {
|
||||||
|
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
|
||||||
|
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(ivParam));
|
||||||
|
return cipher.doFinal(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypts the specified data using the AES algorithm with the provided secret key.
|
* Encrypts the specified data using the AES algorithm with the provided secret key.
|
||||||
*
|
*
|
||||||
@@ -89,9 +105,22 @@ public final class AesUtil {
|
|||||||
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
||||||
*/
|
*/
|
||||||
public static byte[] encrypt(byte[] data, byte[] secret) throws GeneralSecurityException {
|
public static byte[] encrypt(byte[] data, byte[] secret) throws GeneralSecurityException {
|
||||||
|
return encrypt(data, secret, secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypts the specified data using the AES algorithm with the provided secret key.
|
||||||
|
*
|
||||||
|
* @param data the data to be decrypted
|
||||||
|
* @param secret the secret key used for decryption
|
||||||
|
* @param ivParam the iv param
|
||||||
|
* @return the decrypted data as a byte array
|
||||||
|
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
||||||
|
*/
|
||||||
|
public static byte[] decrypt(byte[] data, byte[] secret, byte[] ivParam) throws GeneralSecurityException {
|
||||||
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
|
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
|
||||||
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
|
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(ivParam));
|
||||||
return cipher.doFinal(data);
|
return cipher.doFinal(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,10 +133,24 @@ public final class AesUtil {
|
|||||||
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
||||||
*/
|
*/
|
||||||
public static byte[] decrypt(byte[] data, byte[] secret) throws GeneralSecurityException {
|
public static byte[] decrypt(byte[] data, byte[] secret) throws GeneralSecurityException {
|
||||||
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
|
return decrypt(data, secret, secret);
|
||||||
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
|
}
|
||||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
|
|
||||||
return cipher.doFinal(data);
|
/**
|
||||||
|
* Encrypts the specified string data using the AES algorithm with the provided secret key.
|
||||||
|
*
|
||||||
|
* @param data the string data to be encrypted
|
||||||
|
* @param secret the secret key used for encryption
|
||||||
|
* @param ivParam the iv param
|
||||||
|
* @return the encrypted data encoded in Base64
|
||||||
|
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
||||||
|
*/
|
||||||
|
public static String encrypt(String data, String secret, String ivParam) throws GeneralSecurityException {
|
||||||
|
return Base64.getEncoder().encodeToString(encrypt(
|
||||||
|
data.getBytes(StandardCharsets.UTF_8),
|
||||||
|
secret.getBytes(StandardCharsets.UTF_8),
|
||||||
|
ivParam.getBytes(StandardCharsets.UTF_8)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,8 +162,24 @@ public final class AesUtil {
|
|||||||
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
* @throws GeneralSecurityException if any cryptographic error occurs during encryption
|
||||||
*/
|
*/
|
||||||
public static String encrypt(String data, String secret) throws GeneralSecurityException {
|
public static String encrypt(String data, String secret) throws GeneralSecurityException {
|
||||||
return Base64.getEncoder().encodeToString(encrypt(data.getBytes(StandardCharsets.UTF_8),
|
return encrypt(data, secret, secret);
|
||||||
secret.getBytes(StandardCharsets.UTF_8)));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypts the specified Base64-encoded string data using the AES algorithm with the provided secret key.
|
||||||
|
*
|
||||||
|
* @param data the Base64-encoded string data to be decrypted
|
||||||
|
* @param secret the secret key used for decryption
|
||||||
|
* @return the decrypted string data
|
||||||
|
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
||||||
|
*/
|
||||||
|
public static String decrypt(String data, String secret, String ivParam) throws GeneralSecurityException {
|
||||||
|
var decrypted = decrypt(
|
||||||
|
Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8)),
|
||||||
|
secret.getBytes(StandardCharsets.UTF_8),
|
||||||
|
ivParam.getBytes(StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
return new String(decrypted, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,9 +191,7 @@ public final class AesUtil {
|
|||||||
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
|
||||||
*/
|
*/
|
||||||
public static String decrypt(String data, String secret) throws GeneralSecurityException {
|
public static String decrypt(String data, String secret) throws GeneralSecurityException {
|
||||||
var decrypted = decrypt(Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8)),
|
return decrypt(data, secret, secret);
|
||||||
secret.getBytes(StandardCharsets.UTF_8));
|
|
||||||
return new String(decrypted, StandardCharsets.UTF_8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+18
-13
@@ -1,22 +1,27 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2024-2025 OnixByte.
|
# Copyright (c) 2024-2025 OnixByte
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# you may not use this file except in compliance with the License.
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
# You may obtain a copy of the License at
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
#
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
# See the License for the specific language governing permissions and
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
# limitations under the License.
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
artefactVersion=2.4.0
|
artefactVersion=3.0.0
|
||||||
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
|
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
|
||||||
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
|
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
|
||||||
licenseName=The Apache License, Version 2.0
|
licenseName=MIT
|
||||||
licenseUrl=https://onixbyte.com/projects/onixbyte-toolbox/LICENSE.txt
|
licenseUrl=https://onixbyte.com/projects/onixbyte-toolbox/LICENSE.txt
|
||||||
|
|||||||
Vendored
+16
-10
@@ -1,17 +1,23 @@
|
|||||||
@rem
|
@rem
|
||||||
@rem Copyright 2015 the original author or authors.
|
@rem Copyright (c) 2024-2025 OnixByte
|
||||||
@rem
|
@rem
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
@rem Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@rem you may not use this file except in compliance with the License.
|
@rem of this software and associated documentation files (the "Software"), to deal
|
||||||
@rem You may obtain a copy of the License at
|
@rem in the Software without restriction, including without limitation the rights
|
||||||
|
@rem to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
@rem copies of the Software, and to permit persons to whom the Software is
|
||||||
|
@rem furnished to do so, subject to the following conditions:
|
||||||
@rem
|
@rem
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
@rem The above copyright notice and this permission notice shall be included in all
|
||||||
|
@rem copies or substantial portions of the Software.
|
||||||
@rem
|
@rem
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
@rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
@rem IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@rem FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@rem See the License for the specific language governing permissions and
|
@rem AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
@rem limitations under the License.
|
@rem LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
@rem OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
@rem SOFTWARE.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
|||||||
Reference in New Issue
Block a user