基于自主发明专利的杰林码哈希算法、对称加密算法和无损压缩算法的可文件追踪管控且支持linux和windows的文件压缩包工具SDK1.0版发布,下载链接为:
JLM PACK CSDN下载链接
JLM PACK SDK和软件的官方网站
注意测试授权证书yesine_jlmpack_test.license的有效期到2024年12月,如果需要更长的测试授权,请联系我们!
1、如果你的文件需限制查看人员的设备、账户或时间,可以采用JLM PACK打包,打包后除了有权限的设备,账户或在有效时间内解压,否则均会造成.jlm文件的自毁。通过软件的系统后台可以及时控制打包后的文件传播、自毁等。
2、如果你想实时观察文件的动向,可以用我们的JLM PACK打包软件,能通过系统后台或软件查看当前文件被谁解压过?被谁修改过?是否传播到了本公司以外、某政府以外,或国外?
3、支持linux和windows,最主要的是支持麒麟、鸿蒙,Ununtu,安卓等系统,支持服务器的应用。
4、软件和系统后台均支持独立出售,自定义文件特征(如特殊领域对哈希值的长度,对称加密的密钥长度有特殊要求),也支持定制开发!
一、特色
1、完全采用我国自主发明专利算法,杰林码哈希算法,杰林码对称加密算法以及杰林码无损压缩算法等,该算法均采用了加权概率模型的全新国产编码算法。
采用了随机哈希算法和随机对称加密算法,相同的文件相同的密码,每次加密后的密文均不相同。
2、支持权限管控和文件追踪,比如限制解压的人群、IP、设备和时间,查看文件被那些用户查看过等
3、个人用户基础的压缩解压功能免费
4、SDK需要商业授权,支持自定义分割包,文件包的后缀为.jlm,支持linux和windows,支持x86,x64(RAM和RISC需联系我们获取),支持国产的麒麟。
5、编译码效率快,大概能做到12MB-50MB/s的处理效率,由设备性能而定。
二、JLM PACK软件-支持麒麟、ubuntu和WINDOWS等
1、软件界面
2、该工具软件将于2024年7月正式面向市场,个人基本功能永久免费,企业和政府收费,具体请参考官网:www.jlmpack.com。
3、软件支持换皮肤,中英文等,同步国内外发布!
4、后续将支持防勒索病毒灾难备份,自检错,文件锁,安全策略等功能。
三、JLM PACK SDK
1、Config.h用于宏定义,部分参数可以根据要求进行配置
#pragma once
/**************************************************************************
* @作者 王杰林 2024-05-08
* @功能 配置信息,主要方便调整SDK中部分参数
* @版权 湖南遥昇通信技术有限公司
* @版本 1.0
* @邮件 254908447@qq.com
**************************************************************************/
#ifndef JLMPACKCONFIG_H
#define JLMPACKCONFIG_H
/**************************************************************************
采用预处理指令自定义跨平台的函数接口
**************************************************************************/
#if defined(_WIN32) || defined(_WIN64)
#include "Windows.h"
#include "direct.h"
// windows下删除目录函数为RemoveDirectoryA
#define removeEmptyFolder RemoveDirectoryA
// windows下创建目录函数为_mkdir
#define JlmPack_CreateFolder(path) _mkdir(path)
#else
#include "sys/stat.h"
#include "sys/types.h"
#include "unistd.h"
// linux和unix下的删除目录函数为rmdir
#define removeEmptyFolder rmdir
// linux和unix下的创建目录函数为mkdir
#define JlmPack_CreateFolder(path) mkdir(path, S_IRWXU)
#endif
/**************************************************************************
JLMPACK的一些核心宏定义
**************************************************************************/
// 随机读取文件中READ_BYTE_LIMIT_TO_COMPUTE_HASH个字节用于计算哈希值
#define READ_BYTE_LIMIT_TO_COMPUTE_HASH 1024
// 随机加密的随机数长度,随机数越大安全性越高
#define RANDOM_BYTE_LIMIT 6
// 当前文件的哈希值长度,建议8到16字节
#define HASH_BYTE_LIMIT 8
// 统一规范文件名(不含路径,带后缀)的最大字节数
#define NAME_BYTE_LIMIT 200
// 统一规范路径(带文件名和后缀)的最大字节数
#define URL_BYTE_LIMIT 1000
// 最大允许的目录数,即所有的目录和子目录、文件的总和不能超过CATALOG_MAX_LIMIT,可在此处调整
#define CATALOG_MAX_LIMIT 10000
// 目录嵌套深度,即文件夹下的文件夹,最大嵌套深度
#define FOLDERS_NESTED_MAX_LIMIT 1000
// 哈希值的长度限制
#define JLM_FILE_HASH_BYTE_LIMIT 64
#define PACK_FILE_HASH_BYTE_LIMIT 32
// JLM_EXTRA中部分对象的字节长度限制
#define EXTRA_BYTE_LIMIT 100
// JlmPack_JLMSE函数的两个状态:加解密模式
#define ENCODE_MODEL 0
#define DECODE_MODEL 1
// 日志描述的字节大小
#define NOTE_BYTE_LIMIT 200
// 限制二进制文件读写的最大缓存为10MB,可以设置和调整以适应最佳效率,不能低于4MB,不能太大占内存过多
#define BINARY_FILE_MAX_LIMIT 10485760 //10485760 16777216
// 设置包的最大个数,一般来讲打包的目的是把大量的文件和文件夹打包成为几个压缩包,这里设置为100,能满足很多情况下,注意配合PACK_BYTES_LIMIT设置
#define MAX_NUMBER_PACKS 100
// 将JLM压缩包切割成多个包,每个包最大字节数为PACK_BYTES_LIMIT,通过JLM_FILE.packBytesLength自定义
#define JLMPACK_BYTES_LIMIT 4227858432ULL
#endif
2、JlmPack.h的头文件
#pragma once
/**************************************************************************
* @作者 王杰林 2024-06-20
* @功能 遍历全部目录的文件夹以及文件,并保存到目录对象中,支持linux和windows
* @版权 湖南遥昇通信技术有限公司
* @版本 1.0
* @邮件 254908447@qq.com
**************************************************************************/
#ifndef JLMPACK_H
#define JLMPACK_H
// 包含配置头文件,必不可少
#include "Config.h"
// JLM文件的头部信息,头部信息必须是放在第1个包的初始位置,下面的顺序不能修改的,修改可能会出错
typedef struct
{
unsigned char jlmHeadSign[4]; // JLM压缩包文件的头部标识为{ 'J', 'L', 'M', ' '},音频为{ 'J', 'L', 'M', 'A'},视频为{ 'J', 'L', 'M', 'V'},无法修改,就算传递进来也会被重置
unsigned char consistencyMark[PACK_FILE_HASH_BYTE_LIMIT]; // 用来统一主包和子包以及系统后台信息,具有相同的consistencyMark才算一个JLM文件
unsigned int packID; // 包编号分别为1,2,3,...等等,注意一定是从1开始
unsigned int catalogBytesLength; // 目录的原始字节长度,尚未编码的字节长度,也是jlm文件除了JLM_FILE以外的目录存放长度
unsigned int packSize; // 整个jlm根据packBytesLength切割成packSize个子包
unsigned int packBytesLength; // 单个包的字节数量(默认最大单个包大小为PACK_BYTES_LIMIT字节数)
unsigned int encryptionWindow; // 加密轮函数的字节窗口,自动设定为BINARY_FILE_MAX_LIMIT - 2097152,解码时该值修改后将无法解密
unsigned int extraSize; // 记录JLM_EXTRA的字节数,如果extraSize = 0说明没有JLM_EXTRA,如果extraSize = sizeof(JLM_EXTRA)说明存在JLM_EXTRA
unsigned long long fileBytesLength; // 压缩后的总字节长度,包括了头部信息的字节数,加密压缩后的数字证书和目录以及文件数据等(最大2^64-1个字节)
unsigned char license[JLM_FILE_HASH_BYTE_LIMIT]; // 数字证书的数字指纹,商业授权版:由湖南遥昇通信技术有限公司颁发的SDK授权数字证书哈希值;个人版本由官网申请的个人证书哈希值
}JLM_FILE;
/**************************************************************************************
JLM_CATALOG目录对象,非常重要,是预览目录的重要结构体,仅用于展示JLM压缩包中的目录信息
***************************************************************************************/
typedef struct
{
int ID; // 当前目录的ID
int FID; // 上一层目录的ID号,顶层该ID号为0
char type; // 文件类型,是文件夹还是文件类型,0表示文件夹,1表示文件
char name[NAME_BYTE_LIMIT]; // 当前文件或文件夹的名称,包括了后缀名
unsigned long long byteslength; // 原始文件的字节长度,如果是文件夹,则包括了文件夹下的所有文件,如果是文件则是文件的字节数
unsigned char hv[HASH_BYTE_LIMIT]; // 哈希值(校验或签名),最大支持8个字节(默认是4个字节)
long long time; // 文件创建的时间
}JLM_CATALOG;
/**************************************************************************************
目录列表信息对象,非常重要,是预览目录的重要结构体,也是权限验证的重要结构体
***************************************************************************************/
typedef struct
{
int ID; // 当前目录的ID
int FID; // 上一层目录的ID号,方便进行退回
char name[NAME_BYTE_LIMIT]; // 目录名称
unsigned long long byteslength; // 目录下的所有字节数
long long time; // 目录创建的时间
JLM_CATALOG* CatalogList; // 子目录队列
int CatalogListSize; // 子目录列表规模
}JLM_CATALOGINFOR;
/**************************************************************************************
JLM_EXTRA对象属于可选项和可自定义结构体,主要用于版权控制,不建议随意修改,只能增加
1、主函数采用sizeof(JLM_EXTRA)计算JLM_EXTRA的实际字节数并写入到文件末尾,所以不能定义指针变量
2、存放在JLM文件的最末尾(或者最后一个包),文件末尾从fileLength - extraLength字节开始属于JLM_EXTRA对象
***************************************************************************************/
typedef struct
{
char owner[EXTRA_BYTE_LIMIT]; // 版权拥有人(公司或个人)
char promulgator[EXTRA_BYTE_LIMIT]; // 颁布人,或发行人(公司或个人)
char contact[EXTRA_BYTE_LIMIT]; // 联系方式
char versionNumber[EXTRA_BYTE_LIMIT]; // 版本号
long long datetime; // 发布时的系统时间戳
unsigned char authorization; // 本JLM压缩包对外授权分类,0表示免费,1表示共享授权,2表示商业授权(具体的方式由用户自定义)
unsigned char signature[JLM_FILE_HASH_BYTE_LIMIT]; // 数字签名,采用了JLMHA算法
}JLM_EXTRA;
/**************************************************************************************
日志结构体,即创建、解包、追加和删除均有日志文件输出,输出的日志文件可以在本地生成也可以存储到网络上
本日志文件只记录时间,动作,至于其他更多信息,可以通过LOGS结构体追加信息
***************************************************************************************/
typedef struct
{
// 下面这4个对象属于系统对象严禁修改名字和删除,内容由库自动完成填入
int type; // 0表示创建,1表示解包,2表示插入,3表示删除,4表示修改(一般指部分文件的重命名),5表示预览目录
unsigned char consistencyMark[PACK_FILE_HASH_BYTE_LIMIT]; // 用来统一主包和子包以及系统后台信息
unsigned char fileName[NAME_BYTE_LIMIT]; // 文件名
long long datetime; // 发生的系统时间戳
// 可以在此处追加其他对象,追加的对象和处理请到JLMPackAuthorityControl类中处理
}JLM_LOG;
/**************************************************************************************
VARIABLES变量传递,函数不同则对变量要求不同,请参考各函数的说明
***************************************************************************************/
typedef struct
{
/**************************************************************************
* 授权文件YESINE.license的路径,该路径必须正确而且证书也必须是正确有效才能使用本SDK中的所有函数
**************************************************************************/
unsigned char* licenseFilePath;
/**************************************************************************
* 总字节数totalBytes,和累计字节数Cumulative,主要用于进度条的计算
**************************************************************************/
unsigned long long totalBytes;
unsigned long long cumulativeBytes;
/**************************************************************************
* jlmFile为JLM文件格式信息
* jlmExtra为JLM文件扩展信息
**************************************************************************/
JLM_FILE* jlmFile; // 输入或输出jlm文件头信息,见结构体JLM_FILE
JLM_EXTRA* jlmExtra; // 输入或输出jlm文件扩展信息,见结构体JLM_EXTRA
/**************************************************************************
* RandomBytes为编码前或译码后的随机数数组,随机数是抗量子破解的核心
* RandomBytes_size为随机数数组中字节个数
**************************************************************************/
unsigned char* RandomBytes; // 输入或输出随机数,用于生成密钥
int RandomBytes_size; // 输入或输出随机数的字节数
/**************************************************************************
* Passwords为编码或译码的密码数组,将根据用户的需要是否
* Passwords_size为密码数组中字节个数,Passwords_size >= 0且Passwords_size < 64,不建议太长怕忘记后无法找回
**************************************************************************/
unsigned char* Passwords; // 输入加解密密码,译码时密码是解密的关键
int Passwords_size; // 输入加解密密码长度
/**************************************************************************
* jlmFileUrl为编码后或解码前的jlm文件的路径和文件名,可以包括".jlm"
* 支持XXX.jlm首包路径,也支持XXX_packX.jlm子包路径,任何这样的路径输入给jlmFileUrl均可定位到首包的路径
**************************************************************************/
unsigned char* jlmFileUrl;
/**************************************************************************
* pathList为编码前或解码后的各类文件和文件夹的路径列表,pathList中允许.jlm文件
* pathListSize为pathList中路径的个数
* 注意:编码时pathList为各类文件和文件夹的路径,所以pathListSize大于等于
* 译码时pathList只能是译码后的文件夹路径,且pathListSize只能等于1
**************************************************************************/
unsigned char** pathList; // 待编码文件的路径列表或译码后存放文件的文件夹路径,pathList[i]代表一个路径
int pathListSize; // pathList中路径个数
/**************************************************************************
* 签名的数字证书哈希值(数据指纹),用于计算JLM_FILE.cer
**************************************************************************/
unsigned char* license; // 签名的数字证书哈希值(数据指纹),用于计算JLM_FILE.license
int license_size; // 签名的数字证书哈希值字节长度,fatherCer_size为0时说明无签名,此时JLM_FILE.cer为全0序列
/**************************************************************************
* rule为目录权限规则,用于管理目录打开条件,请参考SDK说明书
**************************************************************************/
short rule; // 权限编号
/**************************************************************************
* IdList为待处理的ID列表,比如删除某些ID、追加文件到某个ID下、译码某些ID对应的文件夹或文件等
* IdList_Size为IdList中ID的个数
**************************************************************************/
int* IdList; // ID列表,主要用于译码、删除和增加,创建JLM文件时IdList无效
int IdList_Size; // IdList中ID的个数
/**************************************************************************
* 临时运算变量,重复使用
**************************************************************************/
unsigned char* InByteArray; // 用于压缩和加密编码的临时输入,包括了文件复制等等
unsigned int InByteArray_Size;
unsigned char* OutByteArray; // 用于解压和解密译码的临时输出,包括了文件复制等等
unsigned int OutByteArray_Size;
unsigned char* WriteOrReadBuff; // 用于写文件,大小和OutByteArray、InByteArray一致
unsigned int WriteOrReadBuff_Size;
/**************************************************************************
* 日志输入信息
**************************************************************************/
JLM_LOG* log; // 日志文件
}VARIABLES;
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************************************
获取授权证书内数字签名的函数
输入:
VARIABLES* vars
返回:
Errsign:错误标识,0无错,大于1为错误
*************************************************************************************/
int JlmPack_GetLicense(VARIABLES* vars);
/*************************************************************************************
JLMHA哈希算法函数,根据输入的数据获取长度为OutByteArray_size的哈希值,返回1表示计算成功
1、根据InByteArray生成哈希值,RandomByte是随机生成的字节值,HashByteArray的第0个字节用于存放RandomByte的值
2、验证的时候,必须将老的哈希值A第一个字节作为RandomByte传递给JLMHA,然后再根据InByteArray计算出新的哈希值B,比较两者是否相同
输入:
RandomByte:生成哈希值时RandomByte为0-255的随机数;检验哈希值时RandomByte必须是哈希值的首个字节(前8个比特)
InByteArray:用于计算哈希值的原始数据
InByteArray_size:InByteArray的字节数
HashByteArray:生成哈希值时HashByteArray中HashByteArray_size个字节必须为0x00;迭代计算哈希值时HashByteArray中HashByteArray_size可以为上一次得出的哈希值
HashByteArray_size:需要生成的哈希值长度,可自定义
返回:
Errsign:错误标识,0无错,大于1为错误
*************************************************************************************/
int JlmPack_JLMHA(unsigned char RandomByte, unsigned char* InByteArray, unsigned int InByteArray_size, unsigned char* HashByteArray, unsigned int HashByteArray_size);
/*************************************************************************************
JLMSE对称加密算法函数,注意本函数不做密码校验,无论密码输入是否正确,均会给出一个译码结果
输入:
RandomBytes:随机数,主要是抗量子计算破解
RandomBytes_size:随机数的长度
Passwords:加密或解码密码
Passwords_size:密码的长度
InByteArray:需要编译码的字节缓存
InByteArray_size:InByteArray的字节数
OutByteArray:加解密后的字节缓存
OutByteArray_size:输入需要编译码的字节数,返回实际编译码的字节数
model:加密模式model = 0,解密模式model = 1
返回:
Errsign:错误标识,0无错,大于0出错
*************************************************************************************/
int JlmPack_JLMSE(unsigned char* RandomBytes, unsigned int RandomBytes_size, unsigned char* Passwords, unsigned int Passwords_size, unsigned char* InByteArray, unsigned int InByteArray_size, unsigned char* OutByteArray, unsigned int* OutByteArray_size, int model);
/*************************************************************************************
创建函数,根据参数相关的信息创建一个jlm压缩包
特别注意:
1、文件或文件夹通过pathList传递
2、编码后jlm文件的路径通过jlmFileUrl传递,必须是带文件名(允许不带后缀.jlm)
3、各权限编号通过rule传递
4、IdList和IdList_Size在本函数内是无效的
5、fatherCer为父亲节点的数字证书的数字指纹,可以为空,如果不为空必须与网站后台或license的指纹一致(fatherCer可以查询用户的数字证书),而且整个jlm文件全部采用fatherCer进行签名
6、密码通过Passwords传递
7、随机数通过RandomBytes传递,建议采用4-16个随机数,这个是防止量子破解的核心,不建议为空
输入:
VARIABLES*:参数变量
返回:
Errsign:错误标识
log中的信息
*************************************************************************************/
int JlmPack_Create(VARIABLES* vars);
/*************************************************************************************
获取权限值的函数,除了JlmPack_Create函数,其他函数在使用前都必须完成权限检验
特别注意:
1、编码后jlm文件的路径通过jlmFileUrl传递,必须是带文件名(允许不带后缀.jlm)
2、权限值通过vars->rule返回
3、权限获取不记录日志
输入:
VARIABLES*:参数变量
返回:
Errsign:错误标识
*************************************************************************************/
int JlmPack_GetRule(VARIABLES* vars);
/*************************************************************************************
解包函数:输入IdList列表,解压和解密出IdList列表下面的所有文件或文件夹,解压需要做权限控制
特别注意:
1、如果解压整个压缩包,仅需在IdList中包括了0的ID号
2、译码后的文件存储路径通过pathList[0]传递,而且仅允许pathListSize = 0
3、待解压的JLM压缩包路径通过jlmFileUrl传递,支持jlmFileUrl = XXX_PackX.jlm(程序会自动找到主文件XXX.jlm)
4、其他的通过对应的参数传递,注意RandomBytes会被本函数覆盖掉
安全方案:
1、用Passwords直接解密jlm文件的目录信息,如果解密错误返回无法解密
2、如果解密正确,则可获得CatalogInfor对象以及rule的值,如果rule表达了需要强制服务器校验,则进行第3步,否则直接译码
3、将rule、JLM_FILE.cer、JLM_FILE.consistencyMark和Username、Mac(本地获取)、CPU编号(本地获取)等等信息经过随机加密后推送给后台系统进行验证
4、验证失败返回NULL,则函数UnpackJlmPackFile将根据rule进行动作
5、如果验证成功,则返回当前文件在服务器上的全部日志信息
输入:
VARIABLES*:参数变量
返回:
Errsign:错误标识
*************************************************************************************/
int JlmPack_Unpack(VARIABLES* vars);
/*************************************************************************************
向Jlm文件中追加新待编码文件的函数,追加的过程不会解密任何文件,仅仅重新组织jlm文件包和修改目录信息
特别注意
1、只能设置IdList_Size = 1且IdList[0] = 某ID号(可以为0,表示新增信息存放在根目录下),意思是把新增信息存放在某个目录ID下,如果当前的ID为文件将自动存储到
2、待添加的文件和文件夹路径通过pathList传递
3、jlm压缩包文件路径通过jlmFileUrl传递,支持jlmFileUrl = XXX_PackX.jlm(程序会自动找到主文件XXX.jlm)
4、其他的通过对应的参数传递
输入:
VARIABLES*:参数变量
返回:
Errsign:错误标识
*************************************************************************************/
int JlmPack_Insert(VARIABLES* vars);
/*************************************************************************************
删除Jlm压缩包中某些文件的函数,删除的过程不会解密任何文件,仅仅重新组织jlm文件包和修改目录信息
特别注意
1、待删除的目录ID号通过IdList传递,此时IdList_Size>=1
2、jlm压缩包文件路径通过jlmFileUrl传递,支持jlmFileUrl = XXX_PackX.jlm(程序会自动找到主文件XXX.jlm)
3、其他的通过对应的参数传递
输入:
VARIABLES*:参数变量
返回:
Errsign:错误标识
*************************************************************************************/
int JlmPack_Delete(VARIABLES* vars);
/*************************************************************************************
重命名某个ID的名称,要求是密码必须正确且权限足够,重命名过程无法修改目录中的任何缀名,防止文件格式错误
特别注意:
1、只能设置IdList_Size = 1且IdList[0] = 某ID号(可以为0,浏览根目录同级的文件和文件夹),每次只能针对一个ID进行重命名
2、jlm压缩包文件路径通过jlmFileUrl传递,支持jlmFileUrl = XXX_PackX.jlm(程序会自动找到主文件XXX.jlm)
3、新的名称用pathList[0]传递,所以pathListSize = 1
输入:
VARIABLES*:参数变量,重点是jlmFileUrl和IdList[0]
返回:
JLM_CATALOGINFOR*:目录信息
*************************************************************************************/
int JlmPack_Rename(VARIABLES* vars);
/*************************************************************************************
预览Jlm压缩包的某个ID下的同级文件和文件夹列表,要求是密码必须正确且权限足够
特别注意:
1、只能设置IdList_Size = 1且IdList[0] = 某ID号(可以为0,浏览根目录同级的文件和文件夹)
如果IdList[0]指向的是文件表示当前文件的同级文件和文件夹
如果IdList[0]指向的是文件夹表示当前文件夹下的同级的文件和文件夹
2、jlm压缩包文件路径通过jlmFileUrl传递,支持jlmFileUrl = XXX_PackX.jlm(程序会自动找到主文件XXX.jlm)
3、其他的通过对应的参数传递
输入:
VARIABLES*:参数变量,重点是jlmFileUrl和IdList[0]
返回:
JLM_CATALOGINFOR*:目录信息
*************************************************************************************/
JLM_CATALOGINFOR* JlmPack_BrowseCatalog(VARIABLES* vars, int* errSign);
#ifdef __cplusplus
}
#endif
#endif
3、main.c程序,各个功能函数的测试!
#include "JlmPack.h"
#include "stdio.h"
#include "stdlib.h"
#include "memory.h"
#include "string.h"
#include "locale.h"
#if defined(_WIN32) || defined(_WIN64)
#include "Windows.h"
#define _WINDOWS
#elif defined(__linux__)
#define _LINUX
#else
#error "Unsupported platform"
#endif
// 检验JlmPack_JLMHA和JlmPack_JLMSE,测试通过了
int main3() { // 3
int errSign = 0;
unsigned int i;
unsigned char* RandomBytes = NULL, * RandomBytes1 = NULL;
unsigned char* InByteArray = NULL;
unsigned char* HashByteArray = NULL;
unsigned char* OutByteArray = NULL, * OutByteArray1 = NULL;
unsigned int InByteArray_size = BINARY_FILE_MAX_LIMIT;
unsigned int OutByteArray_size = BINARY_FILE_MAX_LIMIT * 2;
unsigned int OutByteArray_size1 = BINARY_FILE_MAX_LIMIT * 2;
unsigned char RandomByte;
unsigned char* ucPassword = "";
unsigned int uiPasswordLen = 0;
unsigned char* ucPassword1 = "";
unsigned int uiPassword1Len = 0;
unsigned int RandomBytes_size = 64;
unsigned int HashByteArray_size = 4;
HashByteArray = (unsigned char*)malloc(HashByteArray_size * sizeof(unsigned char));
RandomBytes = (unsigned char*)malloc(RandomBytes_size * sizeof(unsigned char));
RandomBytes1 = (unsigned char*)malloc(RandomBytes_size * sizeof(unsigned char));
InByteArray = (unsigned char*)malloc(InByteArray_size * sizeof(unsigned char));
OutByteArray = (unsigned char*)malloc(OutByteArray_size * sizeof(unsigned char));
OutByteArray1 = (unsigned char*)malloc(OutByteArray_size1 * sizeof(unsigned char));
if (HashByteArray == NULL || RandomBytes == NULL || RandomBytes1 == NULL || InByteArray == NULL || OutByteArray == NULL || OutByteArray1 == NULL) goto ERR;
// 生成随机数
srand((unsigned)time(NULL));
printf("生成%d个随机数:\n", RandomBytes_size);
for (i = 0; i < RandomBytes_size; ++i) {
RandomBytes[i] = rand() % 0xFF;
RandomBytes1[i] = 0x00;
printf("%02X,", RandomBytes[i]);
}
printf("\n\n");
printf("生成%d个随机待编码数据:\n", InByteArray_size);
for (i = 0; i < InByteArray_size; ++i) {
InByteArray[i] = rand() % 0xFF; // 0x01;//
if (i < 1024) printf("%02X,", InByteArray[i]);
}
printf("\n\n");
errSign = JlmPack_JLMSE(RandomBytes, RandomBytes_size, ucPassword, uiPasswordLen, InByteArray, InByteArray_size, OutByteArray, &OutByteArray_size, ENCODE_MODEL);
if (errSign == 0x00) {
printf("编码后的字节为:%d个\n", OutByteArray_size);
for (i = 0; i < OutByteArray_size && i < 1024; ++i) {
printf("%02X,", OutByteArray[i]);
}
}
else {
printf("错误!编号为:%d", errSign);
}
printf("\n\n");
errSign = JlmPack_JLMSE(RandomBytes1, RandomBytes_size, ucPassword1, uiPassword1Len, OutByteArray, OutByteArray_size, OutByteArray1, &OutByteArray_size1, DECODE_MODEL);
if (errSign == 0x00) {
printf("\n\n译码后的随机数为:\n");
for (i = 0; i < RandomBytes_size; ++i) {
printf("%02X,", RandomBytes1[i]);
}
printf("\n");
printf("译码后的字节为:%d个\n", OutByteArray_size1);
for (i = 0; i < OutByteArray_size1; ++i) {
if (OutByteArray1[i] != InByteArray[i]) {
printf("译码错误!");
goto ERR;
}
if (i < 1024) printf("%02X,", OutByteArray1[i]);
}
}
else {
printf("错误!编号为:%d", errSign);
}
printf("\n\n编译码正确!!\n");
// 计算InByteArray的哈希值
RandomByte = rand() % 0xFF;
errSign = JlmPack_JLMHA(RandomByte, InByteArray, InByteArray_size, HashByteArray, HashByteArray_size);
if (errSign == 0x00) {
printf("InByteArray的哈希值:\n");
for (i = 0; i < HashByteArray_size; ++i) {
printf("%02X,", HashByteArray[i]);
}
}
printf("\n\n");
ERR:
if (HashByteArray) free(HashByteArray);
if (RandomBytes) free(RandomBytes);
if (InByteArray) free(InByteArray);
if (OutByteArray) free(OutByteArray);
if (OutByteArray1) free(OutByteArray1);
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
// 测试创建目录,测试通过
int Create() { // 4
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); // en_US.UTF-8
VARIABLES* vars = NULL;
int i, errSign = 0, listSize = 2;
unsigned char* ucPassword = "123456";
unsigned char* owner = "湖南遥昇通信技术有限公司";
unsigned char* promulgator = "马力哥";
unsigned char* contact = "18163682727";
unsigned char* versionNumber = "V1.0.0";
unsigned char* signature = "测试测试!";
unsigned long datetime = 0;
unsigned char authorization = 0;
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 建议为2-8个字节
vars->Passwords_size = (int)(strlen(ucPassword) + 1);
vars->pathListSize = 2;
vars->rule = 0;
vars->pathList = (unsigned char**)malloc(vars->pathListSize * sizeof(unsigned char*));
if (vars->pathList == NULL) goto ERR;
for (i = 0; i < vars->pathListSize; ++i) {
vars->pathList[i] = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->pathList[i] == NULL) goto ERR;
}
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 设置扩展信息
strncpy(vars->jlmExtra->owner, owner, strlen(owner));
vars->jlmExtra->owner[strlen(owner)] = '\0';
strncpy(vars->jlmExtra->promulgator, promulgator, strlen(promulgator));
vars->jlmExtra->promulgator[strlen(promulgator)] = '\0';
strncpy(vars->jlmExtra->contact, contact, strlen(contact));
vars->jlmExtra->contact[strlen(contact)] = '\0';
strncpy(vars->jlmExtra->versionNumber, versionNumber, strlen(versionNumber));
vars->jlmExtra->versionNumber[strlen(versionNumber)] = '\0';
strncpy(vars->jlmExtra->signature, signature, strlen(signature));
vars->jlmExtra->signature[strlen(signature)] = '\0';
vars->jlmExtra->datetime = datetime;
vars->jlmExtra->authorization = authorization;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 此处需要从服务器上获取某个账户的证书指纹或SDK的商业授权下的证书指纹,如果某个账户下有指纹则vars->license_size为指纹的实际长度,否则vars->license_size = 0
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
vars->license_size = 0;
if (vars->license == NULL) goto ERR;
// 开辟临时运算缓存
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// 设定每个包的大小,如果不设置则默认按照JLMPACK_BYTES_LIMIT来设置
vars->jlmFile->packBytesLength = 6291456;
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* url1 = "D:\\CatalogTest";
const char* url2 = "D:\\Lena.bmp";
const char* outurl = "D:\\test.jlm";
const char* licensePath = "D:\\YESINE.license";
#elif defined(_LINUX)
printf("_LINUX\n");
const char* url1 = "/home/wangjielin/Desktop/CatalogTest";
const char* url2 = "/home/wangjielin/Desktop/Lena.bmp";
const char* outurl = "/home/wangjielin/Desktop/test.jlm";
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
#endif
strcpy(vars->licenseFilePath, licensePath);
strcpy(vars->pathList[0], url1);
strcpy(vars->pathList[1], url2);
strcpy(vars->Passwords, ucPassword);
strcpy(vars->jlmFileUrl, outurl);
srand((unsigned)time(NULL));
// 调用创建接口
errSign = JlmPack_Create(vars);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("创建成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->license) free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
if (vars->pathList) {
for (i = vars->pathListSize - 1; i >= 0; --i) if (vars->pathList[i]) free(vars->pathList[i]);
free(vars->pathList);
}
free(vars);
}
}
// 测试解包,测试通过
int Unpack() { // 5
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); //en_US.UTF-8
VARIABLES* vars = NULL;
int i, errSign = 0;
unsigned char* ucPassword = "123456";
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 编码和解码这个值必须相同
vars->Passwords_size = strlen(ucPassword) + 1;
vars->pathListSize = 1;
vars->rule = 0;
vars->license_size = 0;
vars->IdList_Size = 2;
vars->pathList = (unsigned char**)malloc(vars->pathListSize * sizeof(unsigned char*));
if (vars->pathList == NULL) goto ERR;
for (i = 0; i < vars->pathListSize; ++i) {
vars->pathList[i] = (unsigned char*)malloc(URL_BYTE_LIMIT * sizeof(unsigned char*));
if (vars->pathList[i] == NULL) goto ERR;
}
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 同上
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 开辟临时运算缓存,译码过程中开辟相同的缓存大小即可
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// ID列表
vars->IdList = (int*)malloc(vars->IdList_Size * sizeof(int));
if (vars->IdList == NULL) goto ERR;
// 复制密码,去除“\0”
strcpy(vars->Passwords, ucPassword);
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* licensePath = "D:\\YESINE.license";
const char* jlmFileUrl = "D:\\test.jlm";
//const char* jlmFileUrl = "D:\\test_pack4.jlm";
const char* outurl = "D:\\testDecode\\"; // 解码的文件夹路径
// 输入解码ID号
vars->IdList[0] = 0; //2
vars->IdList[1] = 18;
#elif defined(_LINUX)
printf("_LINUX\n");
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
const char* jlmFileUrl = "/home/wangjielin/Desktop/test.jlm";
//const char* jlmFileUrl = "/home/wangjielin/Desktop/test_pack3.jlm";
const char* outurl = "/home/wangjielin/Desktop/testDecode/"; // 解码的文件夹路径
// 输入解码ID号,由于linux和windows的排序可能不一致,译码同一个东西
vars->IdList[0] = 0;
vars->IdList[1] = 18;
#endif
strcpy(vars->licenseFilePath, licensePath);
// jlm的文件路径
strcpy(vars->jlmFileUrl, jlmFileUrl);
// 把outurl赋值给vars->pathList[0]
strcpy(vars->pathList[0], outurl);
printf("vars->pathList[0] = %s\n", vars->pathList[0]);
// 给vars->IdList中的数据
errSign = JlmPack_Unpack(vars);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("译码成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->license) free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
if (vars->IdList) free(vars->IdList);
if (vars->pathList) {
for (i = vars->pathListSize - 1; i >= 0; --i) if (vars->pathList[i]) free(vars->pathList[i]);
free(vars->pathList);
}
free(vars);
}
}
// 联合测试创建和解包
int main5() { // 5
Create();
// 休眠3秒,因为有可能文件还没有写完,就开始执行解包容易出现错误
#ifdef _WINDOWS
Sleep(5000); // windows下暂停3秒
#elif defined(_LINUX)
sleep(5); // linux下暂停3秒
#endif
printf("\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
Unpack();
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
// 测试追加文件,经过测试追加后能正常解包
int main6() { // 6
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); //en_US.UTF-8
VARIABLES* vars = NULL;
int i, errSign = 0;
unsigned char* ucPassword = "123456";
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 编码和解码这个值必须相同
vars->Passwords_size = strlen(ucPassword) + 1;
vars->pathListSize = 2; // 待添加到jlm文件包中的目录
vars->rule = 0;
vars->license_size = 0;
vars->IdList_Size = 1; // 添加文件时只能设置为1,否则将报错
vars->pathList = (unsigned char**)malloc(vars->pathListSize * sizeof(unsigned char*));
if (vars->pathList == NULL) goto ERR;
for (i = 0; i < vars->pathListSize; ++i) {
vars->pathList[i] = (unsigned char*)malloc(URL_BYTE_LIMIT * sizeof(unsigned char*));
if (vars->pathList[i] == NULL) goto ERR;
}
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 同上
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 开辟临时运算缓存,译码过程中开辟相同的缓存大小即可
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// ID列表
vars->IdList = (int*)malloc(vars->IdList_Size * sizeof(int));
if (vars->IdList == NULL) goto ERR;
// 复制密码,去除“\0”
strcpy(vars->Passwords, ucPassword);
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* licensePath = "D:\\YESINE.license";
const char* jlmFileUrl = "D:\\test.jlm";
//const char* jlmFileUrl = "D:\\test_pack5.jlm";
const char* addUrl1 = "D:\\目录测试"; // 待添加的文件路径
const char* addUrl2 = "D:\\中国计算机学会推荐国际学术会议和期刊目录-2022.pdf"; // 待添加的文件路径
// 输入解码ID号
vars->IdList[0] = 0; //2
#elif defined(_LINUX)
printf("_LINUX\n");
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
const char* jlmFileUrl = "/home/wangjielin/Desktop/test.jlm";
//const char* jlmFileUrl = "/home/wangjielin/Desktop/test_pack9.jlm";
const char* addUrl1 = "/home/wangjielin/Desktop/WJLCoding"; // 解码的文件夹路径
const char* addUrl2 = "/home/wangjielin/Desktop/JLMAudio"; // 解码的文件夹路径
// 输入解码ID号,由于linux和windows的排序可能不一致,译码同一个东西
vars->IdList[0] = 3;
#endif
strcpy(vars->licenseFilePath, licensePath);
// jlm的文件路径
strcpy(vars->jlmFileUrl, jlmFileUrl);
// 把outurlX赋值给vars->pathList
strcpy(vars->pathList[0], addUrl1);
strcpy(vars->pathList[1], addUrl2);
printf("vars->pathList[0] = %s\n", vars->pathList[0]);
printf("vars->pathList[1] = %s\n", vars->pathList[1]);
errSign = JlmPack_Insert(vars);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("追加成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->license) free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
if (vars->IdList) free(vars->IdList);
if (vars->pathList) {
for (i = vars->pathListSize - 1; i >= 0; --i) if (vars->pathList[i]) free(vars->pathList[i]);
free(vars->pathList);
}
free(vars);
}
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
// 测试删除某些ID即一下的目录信息,测试通过
int main7() { // 7
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); //en_US.UTF-8
VARIABLES* vars = NULL;
int i, errSign = 0;
unsigned char* ucPassword = "123456";
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 编码和解码这个值必须相同
vars->Passwords_size = strlen(ucPassword) + 1;
vars->pathListSize = 0; // 删除目录,此参数为0
vars->rule = 0;
vars->license_size = 0;
vars->IdList_Size = 3; // 添加文件时只能设置为1,否则将报错
vars->pathList = (unsigned char**)malloc(vars->pathListSize * sizeof(unsigned char*));
if (vars->pathList == NULL) goto ERR;
for (i = 0; i < vars->pathListSize; ++i) {
vars->pathList[i] = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->pathList[i] == NULL) goto ERR;
}
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 同上
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 开辟临时运算缓存,译码过程中开辟相同的缓存大小即可
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// ID列表
vars->IdList = (int*)malloc(vars->IdList_Size * sizeof(int));
if (vars->IdList == NULL) goto ERR;
// 复制密码,去除“\0”
strcpy(vars->Passwords, ucPassword);
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* licensePath = "D:\\YESINE.license";
//const char* jlmFileUrl = "D:\\test.jlm";
const char* jlmFileUrl = "D:\\test_pack2.jlm";
// 输入待删除的ID号,为0时
vars->IdList[0] = 3; //2
vars->IdList[1] = 7;
vars->IdList[2] = 23;
#elif defined(_LINUX)
printf("_LINUX\n");
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
//const char* jlmFileUrl = "/home/wangjielin/Desktop/test.jlm";
const char* jlmFileUrl = "/home/wangjielin/Desktop/test_pack2.jlm";
// 输入待删除的ID号
vars->IdList[0] = 5;
vars->IdList[1] = 18;
vars->IdList[2] = 19;
#endif
strcpy(vars->licenseFilePath, licensePath);
// jlm的文件路径
strcpy(vars->jlmFileUrl, jlmFileUrl);
errSign = JlmPack_Delete(vars);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("删除成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->license) free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
if (vars->IdList) free(vars->IdList);
if (vars->pathList) {
for (i = vars->pathListSize - 1; i >= 0; --i) if (vars->pathList[i]) free(vars->pathList[i]);
free(vars->pathList);
}
free(vars);
}
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
// 测试重命名功能,测试通过
int main8() { // 8
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); //en_US.UTF-8
VARIABLES* vars = NULL;
int i, errSign = 0;
unsigned char* ucPassword = "123456";
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 编码和解码这个值必须相同
vars->Passwords_size = strlen(ucPassword) + 1;
vars->pathListSize = 1; // 重命名需要通过vars->pathList[0]传递新的文件名
vars->rule = 0;
vars->license_size = 0;
vars->IdList_Size = 1; // 每次只能针对一个文件名进行重命名
vars->pathList = (unsigned char**)malloc(vars->pathListSize * sizeof(unsigned char*));
if (vars->pathList == NULL) goto ERR;
for (i = 0; i < vars->pathListSize; ++i) {
vars->pathList[i] = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->pathList[i] == NULL) goto ERR;
}
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 同上
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 开辟临时运算缓存,译码过程中开辟相同的缓存大小即可
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// ID列表
vars->IdList = (int*)malloc(vars->IdList_Size * sizeof(int));
if (vars->IdList == NULL) goto ERR;
// 复制密码,去除“\0”
strcpy(vars->Passwords, ucPassword);
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* licensePath = "D:\\YESINE.license";
//const char* jlmFileUrl = "D:\\test.jlm";
const char* jlmFileUrl = "D:\\test_pack2.jlm";
unsigned char* newName = "草帽女孩.bmp";
// 输入待重命名的ID号,为0时
vars->IdList[0] = 18; //2
#elif defined(_LINUX)
printf("_LINUX\n");
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
//const char* jlmFileUrl = "/home/wangjielin/Desktop/test.jlm";
const char* jlmFileUrl = "/home/wangjielin/Desktop/test_pack2.jlm";
unsigned char* newName = "草帽女孩.bmp";
// 输入待重命名的ID号
vars->IdList[0] = 18; //2
#endif
strcpy(vars->licenseFilePath, licensePath);
// jlm的文件路径
strcpy(vars->jlmFileUrl, jlmFileUrl);
strcpy(vars->pathList[0], newName);
errSign = JlmPack_Rename(vars);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("重命名成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->license)free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
if (vars->IdList) free(vars->IdList);
if (vars->pathList) {
for (i = vars->pathListSize - 1; i >= 0; --i) if (vars->pathList[i]) free(vars->pathList[i]);
free(vars->pathList);
}
free(vars);
}
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
// 预览目录测试
int main9() { // 9
// 设置为""的目的是跟随系统,支持windows和linux
setlocale(LC_ALL, ""); //en_US.UTF-8
JLM_CATALOGINFOR* catalogs = NULL;
VARIABLES* vars = NULL;
int i, errSign = 0;
unsigned char* ucPassword = "123456";
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
// 设置里面的参数
vars->RandomBytes_size = RANDOM_BYTE_LIMIT; // 编码和解码这个值必须相同
vars->Passwords_size = strlen(ucPassword) + 1;
vars->rule = 0;
vars->license_size = 0;
vars->IdList_Size = 1; // 预览仅针对一个ID号
vars->jlmFile = (JLM_FILE*)malloc(sizeof(JLM_FILE));
if (vars->jlmFile == NULL) goto ERR;
// vars->jlmExtra = NULL;
vars->jlmExtra = (JLM_EXTRA*)malloc(sizeof(JLM_EXTRA));
if (vars->jlmExtra == NULL) goto ERR;
// 开辟随机数的缓存空间
vars->RandomBytes = (unsigned char*)malloc(vars->RandomBytes_size * sizeof(unsigned char));
vars->Passwords = (unsigned char*)malloc(vars->Passwords_size * sizeof(unsigned char));
if (vars->RandomBytes == NULL || vars->Passwords == NULL) goto ERR;
// 开辟jlm路径的缓存空间
vars->jlmFileUrl = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->jlmFileUrl == NULL) goto ERR;
// 同上
vars->license = (unsigned char*)malloc(JLM_FILE_HASH_BYTE_LIMIT);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// 开辟临时运算缓存,译码过程中开辟相同的缓存大小即可
vars->WriteOrReadBuff_Size = vars->OutByteArray_Size = vars->InByteArray_Size = BINARY_FILE_MAX_LIMIT;
vars->InByteArray = (unsigned char*)malloc(vars->InByteArray_Size * sizeof(unsigned char));
vars->OutByteArray = (unsigned char*)malloc(vars->OutByteArray_Size * sizeof(unsigned char));
vars->WriteOrReadBuff = (unsigned char*)malloc(vars->WriteOrReadBuff_Size * sizeof(unsigned char));
if (vars->InByteArray == NULL || vars->OutByteArray == NULL || vars->WriteOrReadBuff == NULL) goto ERR;
// 开辟日志文件
vars->log = (JLM_LOG*)malloc(sizeof(JLM_LOG));
if (vars->log == NULL) goto ERR;
// ID列表
vars->IdList = (int*)malloc(vars->IdList_Size * sizeof(int));
if (vars->IdList == NULL) goto ERR;
// 复制密码,去除“\0”
strcpy(vars->Passwords, ucPassword);
// 区分windows和linux
#ifdef _WINDOWS
printf("_WINDOWS\n");
const char* licensePath = "D:\\YESINE.license";
//const char* jlmFileUrl = "D:\\test.jlm";
const char* jlmFileUrl = "D:\\test_pack2.jlm";
// 输入待预览的ID号
vars->IdList[0] = 18; //2
#elif defined(_LINUX)
printf("_LINUX\n");
const char* licensePath = "/home/wangjielin/Desktop/YESINE.license";
//const char* jlmFileUrl = "/home/wangjielin/Desktop/test.jlm";
const char* jlmFileUrl = "/home/wangjielin/Desktop/test_pack2.jlm";
// 输入待预览的ID号
vars->IdList[0] = 18; //2
#endif
strcpy(vars->licenseFilePath, licensePath);
// jlm的文件路径
strcpy(vars->jlmFileUrl, jlmFileUrl);
// 读取目录
catalogs = JlmPack_BrowseCatalog(vars, &errSign);
printf("errSign = %d\n", errSign);
if (errSign == 0) {
printf("预览成功!\n");
printf("vars->log->type = %d\n", vars->log->type);
printf("vars->log->fileName = %s\n", vars->log->fileName);
printf("vars->log->consistencyMark = ");
for (i = 0; i < PACK_FILE_HASH_BYTE_LIMIT; ++i) {
printf("%02X,", vars->log->consistencyMark[i]);
}
printf("\n");
printf("vars->log->datetime = %lld\n", vars->log->datetime);
printf("vars->totalBytes = %lld, vars->cumulativeBytes = %lld\n", vars->totalBytes, vars->cumulativeBytes);
// 打印测试
printf("catalogs->ID = %d\n", catalogs->ID);
printf("catalogs->FID = %d\n", catalogs->FID);
printf("catalogs->name = %s\n", catalogs->name);
printf("catalogs->time = %lld\n", catalogs->time);
printf("catalogs->byteslength = %llu\n", catalogs->byteslength);
printf("catalogs->CatalogListSize = %d\n", catalogs->CatalogListSize);
for (i = 0; i < catalogs->CatalogListSize; ++i) {
printf("%d %d %d %s %llu\n", catalogs->CatalogList[i].ID, catalogs->CatalogList[i].type, catalogs->CatalogList[i].FID, catalogs->CatalogList[i].name, catalogs->CatalogList[i].byteslength);
}
printf("\n");
}
ERR:
if (vars) {
if (vars->InByteArray) free(vars->InByteArray);
if (vars->OutByteArray) free(vars->OutByteArray);
if (vars->WriteOrReadBuff) free(vars->WriteOrReadBuff);
if (vars->log) free(vars->log);
if (vars->jlmFile) free(vars->jlmFile);
if (vars->jlmExtra) free(vars->jlmExtra);
if (vars->RandomBytes) free(vars->RandomBytes);
if (vars->Passwords) free(vars->Passwords);
if (vars->jlmFileUrl) free(vars->jlmFileUrl);
if (vars->IdList) free(vars->IdList);
if (vars->license)free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
free(vars);
}
// 注意catalogs必须释放
if (catalogs) {
if (catalogs->CatalogList) free(catalogs->CatalogList);
free(catalogs);
}
// 结束
#ifdef _WINDOWS
system("pause");
return 0;
#elif defined(_LINUX)
return 0;
#endif
}
int main() { // 11
setlocale(LC_ALL, "");
VARIABLES* vars = NULL;
int i, errSign = 0;
const char* licensePath = "D:\\YESINE.license"; //
vars = (VARIABLES*)malloc(sizeof(VARIABLES));
if (vars == NULL) goto ERR;
vars->license_size = JLM_FILE_HASH_BYTE_LIMIT;
vars->license = (unsigned char*)malloc(vars->license_size);
if (vars->license == NULL) goto ERR;
vars->licenseFilePath = (unsigned char*)malloc(URL_BYTE_LIMIT);
if (vars->licenseFilePath == NULL) goto ERR;
// YESINE.license路径
strcpy(vars->licenseFilePath, licensePath);
errSign = JlmPack_GetLicense(vars);
ERR:
if (vars) {
if (vars->license) free(vars->license);
if (vars->licenseFilePath) free(vars->licenseFilePath);
free(vars);
}
system("pause");
return 0;
}