* fixing security issues with rsa padding
Signed-off-by: CubeBit <denis-seredenko@ukr.net>
This commit is contained in:
@@ -10,7 +10,7 @@ import java.util.Base64;
|
|||||||
|
|
||||||
public class EncryptionUtil {
|
public class EncryptionUtil {
|
||||||
|
|
||||||
public static final int RSA_KEY_SIZE = 4096;
|
public static final int RSA_KEY_SIZE = 2048;
|
||||||
|
|
||||||
public static final int AES_KEY_SIZE = 256;
|
public static final int AES_KEY_SIZE = 256;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class EncryptionUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String encryptWithRSA(String data, PublicKey publicKey) throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException {
|
public static String encryptWithRSA(String data, PublicKey publicKey) throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException {
|
||||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||||
|
|
||||||
byte[] encryptedMessage = cipher.doFinal(data.getBytes());
|
byte[] encryptedMessage = cipher.doFinal(data.getBytes());
|
||||||
@@ -59,7 +59,7 @@ public class EncryptionUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String decryptWithRSA(String encryptedData, PrivateKey pk) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
public static String decryptWithRSA(String encryptedData, PrivateKey pk) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
|
||||||
cipher.init(Cipher.DECRYPT_MODE, pk);
|
cipher.init(Cipher.DECRYPT_MODE, pk);
|
||||||
|
|
||||||
byte[] decryptedMessage = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
|
byte[] decryptedMessage = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
|
||||||
|
|||||||
Reference in New Issue
Block a user