Created
December 17, 2022 04:19
-
-
Save sopanatx/70812f71d868e3157577a4effd0f36f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
@NotNull | |
public String encrypt(@NotNull String plainText, @NotNull String key) { | |
Intrinsics.checkNotNullParameter(plainText, "plainText"); | |
Intrinsics.checkNotNullParameter(key, "key"); | |
Cipher cipher = getCipher(1, key); | |
byte[] plainTextBytes = plainText.getBytes(Charsets.UTF_8); | |
Intrinsics.checkNotNullExpressionValue(plainTextBytes, "(this as java.lang.String).getBytes(charset)"); | |
byte[] encryptedBytes = Base64.encode(cipher.doFinal(plainTextBytes)); | |
Intrinsics.checkNotNullExpressionValue(encryptedBytes, "encode(encryptedBytes)"); | |
return StringsKt__StringsJVMKt.replace$default(new String(encryptedBytes, Charsets.UTF_8), "(\\r|\\n|\\r\\n)+", "", false, 4, (Object) null); | |
} | |
@Override | |
@NotNull | |
public String generateRandomString(int length) { | |
SecureRandom random = new SecureRandom(); | |
StringBuilder builder = new StringBuilder(length); | |
char[] characters = this.characterArray.getCharacters(); | |
if (length > 0) { | |
int i = 0; | |
do { | |
i++; | |
builder.append(characters[random.nextInt(characters.length)]); | |
} while (i < length); | |
} | |
return builder.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment