파일에 mmap을 사용하십시오. 파일은 메모리의 데이터 스트림으로 열립니다. 예를 들어, 대형 (예를 들어, 400GB) 파일에있는 파일에 XOR의 각 바이트는 것을 간단한 메모리 변경 기능 : http://unixhelp.ed.ac.uk/CGI/man-cgi?mmap가 에게 당신이 정말로 찾아야한다하더라도 :
// The encryption function
void xor_ram (unsigned char *buffer, long len) {
while (len--) *buffer ^= *buffer++;
}
// The file we want to encrypt
int fd = open ("/path/to/file", O_RDWR);
// Figure out the file length
FILE *tmpf = fdopen (fd, "r");
fseek (tmpf, 0, SEEK_END);
long length = ftell (tmpf);
// Memory map the file using the fd
unsigned char *mapped_file = mmap (NULL, length,
PROT_READ | PROT_WRITE, MAP_PRIVATE,
fd, 0);
// Call the encryption function
xor_ram (mapped_file, length);
// All done now
munmap (mapped_file, length);
close (fd);
당신이있어 mmap에 대한 맨 페이지를 읽을 수 있습니다 특정 플랫폼에서 mmap에 관한 문서 (어떤 종류의 유닉스 시스템을 사용하고 있다면 man mmap, 그렇지 않다면 플랫폼 라이브러리를 찾는다).
CTR 또는 XTS와 같은 [블록 암호화 모드] (https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation)를 사용하는 경우 임의 액세스는 문제가되지 않습니다. 자세한 내용은 http://stackoverflow.com/a/22958889/371137을 참조하십시오. – Perseids