Decryption of AES encrypted data in custom DataSource
I am writing cusom DataSource for decryption of AES encrypted data. Help me rectify the error.
have initialized FileInputeStream and then wrapped it in CipherInputStream
@Override public long open(DataSpec dataSpec) throws IOException { .... cipherInputStream = new CipherInputStream(inputStream, cipher); .... }
and in
@Override public int read(byte[] buffer, int offset, int readLength) throws IOException { ... bytesRead = cipherInputStream.read(buffer, offset, bytesToRead); ... }
I get error IllegalStateException: Top bit not zero: -1136244354
is this a right approach?
That error means your DataSource is either returning invalid media, or violating the contract of the DataSource interface. I can't see anything obviously wrong with your approach, but since this is a custom component we're unfortunately unable to provide direct assistance.
after adding
cipherInputStream.skip(dataSpec.position);
in open(...){...}
works good