* deleted unused imports
Signed-off-by: CubeBit <denis-seredenko@ukr.net>
This commit is contained in:
@@ -5,7 +5,6 @@ import javax.crypto.spec.GCMParameterSpec;
|
|||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
@@ -34,10 +33,6 @@ public class EncryptionUtil {
|
|||||||
return Base64.getEncoder().encodeToString(publicKey.getEncoded());
|
return Base64.getEncoder().encodeToString(publicKey.getEncoded());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String privateKeyToString(PrivateKey privateKey) {
|
|
||||||
return Base64.getEncoder().encodeToString(privateKey.getEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PublicKey stringToPublicKey(String encodedKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
public static PublicKey stringToPublicKey(String encodedKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
byte[] decodedKey = Base64.getDecoder().decode(encodedKey.getBytes());
|
byte[] decodedKey = Base64.getDecoder().decode(encodedKey.getBytes());
|
||||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);
|
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);
|
||||||
@@ -47,14 +42,6 @@ public class EncryptionUtil {
|
|||||||
return factory.generatePublic(keySpec);
|
return factory.generatePublic(keySpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PrivateKey stringToPrivateKey(String encodedKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
||||||
byte[] decodedKey = Base64.getDecoder().decode(encodedKey.getBytes());
|
|
||||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);
|
|
||||||
|
|
||||||
KeyFactory kf = KeyFactory.getInstance("RSA");
|
|
||||||
return kf.generatePrivate(keySpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
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/OAEPWithSHA-256AndMGF1Padding");
|
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user