Untitled

 avatar
unknown
plain_text
a year ago
698 B
17
Indexable
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);
        }
    }
Editor is loading...
Leave a Comment