Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Encrypt the 1st MB of a video file without rewriting it  RSS feed

 
elnoxv vie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am writing an app which requires me to encrypt the 1st MB of a video file by modifying it rather than rewriting it.

Have a look at the RandomAccessFile? but i can't make sense of it. how do i get the 1st MB of the bytes and write it back to the same file?

sample code:




This function doesn't seem to work. Once decrypted the file is no longer the same file.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

When you read from or write to a RandomAccessFile, its internal file pointer moves on. You have to reset it, using the seek method.
 
elnoxv vie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Welcome to the Ranch!

When you read from or write to a RandomAccessFile, its internal file pointer moves on. You have to reset it, using the seek method.


Thanks Rob, it works now.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Henry Wong
author
Sheriff
Posts: 22818
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encrypting should change the size of the file (and encrypting part of the file should change the size just for that part) -- so how are you going to encrypt the first 1MB, and not have to move the rest of the file? In other words, you will most likely have to rewrite the file, if only to move the data within the file.

Henry
 
elnoxv vie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Encrypting should change the size of the file (and encrypting part of the file should change the size just for that part) -- so how are you going to encrypt the first 1MB, and not have to move the rest of the file? In other words, you will most likely have to rewrite the file, if only to move the data within the file.

Henry


Hi Henry, Yes. However, Encryption using AES/CTR/NOPADDING doesn't increase the size of the output. Strange though, if it's video that i am encrypting it seems to corrupt some video on certain devices but not all. Any ideas?

I am using exactly 8192 which is divisible by 16 bytes.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!