Skip to content

Commit

Permalink
This may fix something, I don't know yet
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Oct 2, 2023
1 parent ce3fee2 commit 95fda89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ class GoogleAuth(
CredentialData(body.accessToken, Instant.now().plusSeconds(body.expiresIn.toLong()))
}
STATUS_CODE_BAD_REQUEST -> {
val body = objectMapper.readValue<ErrorData>(response.body!!.string())
val bodyRaw = response.body!!.string()
LOGGER.error("[Google] Access Token Request: $bodyRaw")
val body = objectMapper.readValue<ErrorData>(bodyRaw)
response.close()

LOGGER.error("[Google] Access Token Request: $body")

if (body.error == "invalid_grant") {
LOGGER.debug(DEFAULT, "[Google] Access to resource has been revoked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ class AESEncryption(privateKey: String) {

private val ivParameterSpec = IvParameterSpec(key1.toByteArray(StandardCharsets.UTF_8))
private val secretKeySpec = SecretKeySpec(privateKey.toByteArray(StandardCharsets.UTF_8), "AES")
private var cipher: Cipher?
private var encryptCipher: Cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
private var decryptCipher: Cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")

init {
try {
this.cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
} catch (ignore: Exception) {
this.cipher = null
}
this.encryptCipher.init(Cipher.ENCRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
this.decryptCipher.init(Cipher.ENCRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
}

@Deprecated("Use #decryptFixed(string) instead")
fun encrypt(data: String): Mono<String> {
return Mono.fromCallable {
this.cipher?.init(Cipher.ENCRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
val encrypted = this.cipher?.doFinal(data.toByteArray(StandardCharsets.UTF_8))
val encrypted = this.encryptCipher.doFinal(data.toByteArray(StandardCharsets.UTF_8))

Base64.encodeBase64String(encrypted)
}.doOnError {
Expand All @@ -43,8 +40,7 @@ class AESEncryption(privateKey: String) {

fun encryptFixed(data: String): String {
return try {
this.cipher?.init(Cipher.ENCRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
val encrypted = this.cipher?.doFinal(data.toByteArray(StandardCharsets.UTF_8))
val encrypted = this.encryptCipher.doFinal(data.toByteArray(StandardCharsets.UTF_8))

Base64.encodeBase64String(encrypted)
} catch (ex: Exception) {
Expand All @@ -56,8 +52,7 @@ class AESEncryption(privateKey: String) {
@Deprecated("Use #decryptFixed(string) instead")
fun decrypt(data: String): Mono<String> {
return Mono.fromCallable {
this.cipher?.init(Cipher.DECRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
val decrypted = this.cipher?.doFinal(Base64.decodeBase64(data))
val decrypted = this.decryptCipher.doFinal(Base64.decodeBase64(data))

String(decrypted!!, StandardCharsets.UTF_8)
}.doOnError {
Expand All @@ -69,8 +64,7 @@ class AESEncryption(privateKey: String) {

fun decryptFixed(data: String): String {
return try {
this.cipher?.init(Cipher.DECRYPT_MODE, this.secretKeySpec, this.ivParameterSpec)
val decrypted = this.cipher?.doFinal(Base64.decodeBase64(data))
val decrypted = this.decryptCipher.doFinal(Base64.decodeBase64(data))

String(decrypted!!, StandardCharsets.UTF_8)
} catch (ex: Exception) {
Expand Down

0 comments on commit 95fda89

Please sign in to comment.