Posts

Showing posts with the label encryption

AES CTR Encryption in Java under different Android Version

AES CTR Encryption in Java under different Android Version I was trying to encode a string using Cipher with "AES/CTR/PKCS5PADDING" but I got different encrypted string (different in the length of the string as well) when the same coding is used in a physical android phone (android 4.4 API 19) and virtual android device (Nexus 5X API 26) under the same keygen. The virtual android device could generate string with 32bytes but the physical one couldn't (which has the same length of the string to be encoded). Would it be the problem of cipher which is not supported for old version android? Below is the testing coding used: byte Input = "Testing123".getBytes(); byte encoded_key = Base64.decode("ABCDEFGHIJKLMNOPQABCDEFGHIJKLMNOPQABCDEFGHI", Base64.DEFAULT); SecretKey secretKey = new SecretKeySpec(encoded_key, 0, encoded_key.length, "AES"); byte iv = new byte[128 / 8]; Cipher cipher = Cipher.getInstance("AES/CTR/PKCS5PADDIN...

Using java to encrypt integers

Using java to encrypt integers I'm trying to encrypt some integers in java using java.security and javax.crypto. The problem seems to be that the Cipher class only encrypts byte arrays. I can't directly convert an integer to a byte string (or can I?). What is the best way to do this? Should I convert the integer to a string and the string to byte? This seems too inefficient. Does anyone know a quick/easy or efficient way to do it? Please let me know. Thanks in advance. jbu Hmm.. are you going between different Endianness? If so that would cause those integers to be incorrect when you converted them back from the byte array.. – SCdF Nov 26 '08 at 19:19 Apparerntly "Java virtual machine always used big-endian", so I guess it's not an issue. – SCdF No...