encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

decrypt string in flutter dart

Open preetideswal opened this issue 2 years ago • 1 comments

Java Code: public String decrypt(String encryptedText) throws Exception { try { byte[] decryptedTextBytes = null; byte[] encryptedTextBytes = Base64.decode(encryptedText, Base64.NO_WRAP); final SecretKeySpec secretSpec = sha256("myCheckSumValue"); decryptedTextBytes = decrypt(secretSpec, ivBytes, encryptedTextBytes); return new String(decryptedTextBytes, StandardCharsets.UTF_8); } catch (Exception e) { msg_display.setText("QR code was not scanned properly ! ! ! ! ! !"); throw new RuntimeException(e); } } public SecretKeySpec sha256(String base) { try { final MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = base.getBytes(StandardCharsets.UTF_8); digest.update(hash, 0, hash.length); byte[] key = digest.digest(); return new SecretKeySpec(key, "AES"); } catch (Exception ex) { throw new RuntimeException(ex); } } public byte[] decrypt(final SecretKeySpec key, final byte[] iv, final byte[] decodedCipherText) throws Exception { final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec ivSpec = new IvParameterSpec(iv); cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); return cipher.doFinal(decodedCipherText); }

But i don't know how i decrypt in flutter

Thankyou

preetideswal avatar Aug 12 '21 13:08 preetideswal

yes, there is no documentation about to decrypted of string encrypter aes.

yogithesymbian avatar Dec 02 '21 09:12 yogithesymbian