Cipher classes..

33 views
Skip to first unread message

Gareth Murfin

unread,
Sep 4, 2019, 3:06:04 PM9/4/19
to CodenameOne Discussions
Im trying to convert this code to CN1, is there any equivalent to Cipher and MessageDigest classes?
 public static byte[] decrypt(bytes[] key, byte[] bytesToDecrypt) {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            int blockSize = cipher.getBlockSize();

            byte[] iv = Arrays.copyOfRange(bytesToDecrypt, 0, blockSize);
            byte[] encryptedData = Arrays.copyOfRange(bytesToDecrypt, blockSize, bytesToDecrypt.length);

            IvParameterSpec ivspec = new IvParameterSpec(iv);
            SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
            cipher.init(Cipher.DECRYPT_MODE, secretKey, ivspec);

            return cipher.doFinal(encryptedData);
        } catch (Exception e) {
            Log.e(TAG, "Error while decrypting: " + e.toString());
        }
        return null;
}
public byte[] sha256Hash(String inputCode) {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    return digest.digest(inputCode.getBytes(StandardCharsets.UTF_8));
}


Shai Almog

unread,
Sep 4, 2019, 10:35:28 PM9/4/19
to CodenameOne Discussions
No.
But there's a community member who implemented this already: https://github.com/jsfan3/SHA-Codename-One

Gareth Murfin

unread,
Sep 5, 2019, 1:08:50 PM9/5/19
to CodenameOne Discussions
Thanks Shai! What a great community!!..
Reply all
Reply to author
Forward
0 new messages