From 15209139103655a28f64b19e01c49ee6c6cafe04 Mon Sep 17 00:00:00 2001 From: BoomEaro <21033866+BoomEaro@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:50:16 +0300 Subject: [PATCH] Use SunJCE provider for chiper --- .../src/main/java/net/md_5/bungee/EncryptionUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 27c5b0664a4..a8b77678201 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -11,12 +11,12 @@ import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; +import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.Signature; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; -import java.util.Arrays; import java.util.Base64; import java.util.Random; import java.util.UUID; @@ -108,17 +108,17 @@ public static boolean check(PlayerPublicKey publicKey, EncryptionResponse resp, return signature.verify( resp.getEncryptionData().getSignature() ); } else { - Cipher cipher = Cipher.getInstance( "RSA" ); + Cipher cipher = Cipher.getInstance( "RSA/ECB/PKCS1Padding" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); byte[] decrypted = cipher.doFinal( resp.getVerifyToken() ); - return Arrays.equals( request.getVerifyToken(), decrypted ); + return MessageDigest.isEqual( request.getVerifyToken(), decrypted ); } } public static SecretKey getSecret(EncryptionResponse resp, EncryptionRequest request) throws GeneralSecurityException { - Cipher cipher = Cipher.getInstance( "RSA" ); + Cipher cipher = Cipher.getInstance( "RSA/ECB/PKCS1Padding" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); return new SecretKeySpec( cipher.doFinal( resp.getSharedSecret() ), "AES" ); } @@ -143,7 +143,7 @@ private static PublicKey getPubkey(byte[] b) throws GeneralSecurityException public static byte[] encrypt(Key key, byte[] b) throws GeneralSecurityException { - Cipher hasher = Cipher.getInstance( "RSA" ); + Cipher hasher = Cipher.getInstance( "RSA/ECB/PKCS1Padding" ); hasher.init( Cipher.ENCRYPT_MODE, key ); return hasher.doFinal( b ); }