Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
698 B
12
Indexable
Never
public static String decryptDataUsingPrivateKey(String qrData, String privateKey) {
        try {
            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            PrivateKey rsaPrivateKey = getPrivateKey(privateKey);
            cipher.init(Cipher.DECRYPT_MODE, rsaPrivateKey);
            byte[] encryptedBytes = Base64.decodeBase64(qrData);
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
            return new String(decryptedBytes);
        } catch (Throwable throwable) {
            log.error(ErrorMessages.INVALID_ENCRYPTED_DATA, throwable.getMessage());
            throw new BadRequestException(ErrorMessages.INVALID_ENCRYPTED_DATA);
        }
    }
Leave a Comment