コード例 #1
0
ファイル: example.c プロジェクト: 01BTC10/blobcrypt
int
main(int argc, char *argv[])
{
    struct stat st;
    int         fd;
    int         ret = -1;

    if (argc != 3) {
        usage();
    }
    if ((fd = open(argv[2], O_RDONLY)) == -1) {
        perror("open");
        return 1;
    }
    if (fstat(fd, &st) != 0) {
        perror("fdstat");
        (void) close(fd);
        return 1;
    }
    if (!S_ISREG(st.st_mode)) {
        fprintf(stderr, "[%s] is not a regular file\n", argv[2]);
        (void) close(fd);
        return 1;
    }
    sodium_init();
    if (strcmp(argv[1], "-e") == 0) {
        ret = file_encrypt(fd, st.st_size);
    } else if (strcmp(argv[1], "-d") == 0) {
        ret = file_decrypt(fd);
    } else {
        usage();
    }
    close(fd);

    if (ret != 0) {
        fprintf(stderr, "Aborted.\n");
    }

    return -ret;
}
コード例 #2
0
int TestFile()
{
	printf("This is File Encrypt test\n");

	unsigned char buff_password[] = "01234567890abcef";

	printf("文件加密中.............\n");
	if (file_encrypt(ENCRYPT_AES, "2.jpg", "2.en", buff_password) != 0)
	{
		printf("file encrypt failed\n");
		exit(0);//TODO
	}

	printf("文件解密中.............\n");
	if (file_decrypt(ENCRYPT_AES, "2.en", "3.jpg", buff_password) != 0)
	{
		printf("file decrypt failed\n");
		exit(0);
	}

	return 0;
}