![图片[1]-temcrypt:基于随着时间的推移可扩展的复杂性的进化加密框架-IT熊技术站](https://www.cutrui.cn/wp-content/uploads/2023/09/image-37-1024x512.png)
下一代加密
temcrypt SDK
temcrypt 专注于保护高度敏感的数据,是一种先进的多层数据进化加密机制,可随着时间的推移提供可扩展的复杂性,并且能够抵抗常见的暴力攻击。
您可以在部署时创建自己的应用程序、脚本和自动化。
知识
了解temcrypt代表什么、促使我创建它的功能和灵感等等。阅读知识文档。这对你来说非常重要。
兼容性
temcrypt 与 Node.js v18 或主要的现代 Web 浏览器兼容,允许您在各种环境中使用它。
入门
temcrypt 使用的唯一依赖项是crypto-js
用于处理加密算法,如AES-256、SHA-256和一些编码器,并fs
用于 Node.js 的文件处理
要使用 temcrypt,您需要安装Node.js。然后,您可以使用 npm 安装 temcrypt:npm install temcrypt
之后,将其导入到您的代码中,如下所示:const temcrypt = require(“temcrypt”);
包括其依赖项的自动安装功能,因此您不必担心手动安装它们。只需运行该temcrypt.js
库,依赖项就会自动安装,然后在代码中调用它,这样做是为了便于移植:node temcrypt.js
或者,您可以通过包含以下脚本标签直接在浏览器中使用 temcrypt:<script src=”temcrypt.js”></script>
或缩小:<script src=”temcrypt.min.js”></script>
您还可以从CDN调用您网站或 Web 应用程序上的库:<script src=”https://cdn.jsdelivr.net/gh/jofpin/temcrypt/temcrypt.min.js”></script>
用法
加密与解密
temcrypt 提供encrypt
和等功能decrypt
来安全地保护和披露您的信息。
参数
dataString
( string ):要加密的字符串数据。dataFiles
( string ):要加密的文件路径。提供dataString
或dataFiles
。mainKey
( string ):用于加密的主密钥(私有)。extraBytes
(number,可选):添加到加密中的附加字节。是 temcrypt 加密过程中使用的可选参数。它允许您向加密数据添加额外的字节,从而增加加密的复杂性,这需要更多的处理能力来解密。它还可以通过改变加密的权重来使模式丢失。
Returns
- 如果成功:
status
( boolean ):true
表示解密成功。hash
( string ):为加密数据的合法性验证而生成的唯一哈希值。dataString
( string ) 或dataFiles
:解密的字符串或解密文件的文件路径,具体取决于输入。updatedEncryptedData
( string ): 解密后更新的加密数据。解密后更新的加密数据。每次加密被解密时,输出都会更新,因为 mainKey 会更改其顺序并保存上次解密的新日期。creationDate
( string ):加密数据的创建日期。lastDecryptionDate
( string ):上次成功解密数据的日期。
- 如果
dataString
提供:hash
( string ):为加密数据的合法性验证而生成的唯一哈希值。mainKey
( string ):用于加密的主密钥(私有)。timeKey
( string ): 加密的时间密钥(私有)。dataString
( string ):加密后的字符串。extraBytes
(number,可选):用于加密的额外字节。
- 如果
dataFiles
提供:hash
( string ):为加密数据的合法性验证而生成的唯一哈希值。mainKey
( string ):用于加密的主密钥。timeKey
( string ): 加密的时间密钥。dataFiles
( string ): 加密文件的文件路径。extraBytes
(number,可选):用于加密的额外字节。
- 如果解密失败:
status
( boolean ):false
表示解密失败。error_code
( number ):错误代码,指示解密失败的原因。message
( string ):解释解密失败的描述性错误消息。
以下是如何使用 temcrypt 的一些示例。请注意,加密时,您必须输入密钥并保存加密信息的小时和分钟。要解密信息,您必须在随后几天的同一小时和同一分钟使用相同的主密钥:
加密字符串
const dataToEncrypt = "Sensitive data";
const mainKey = "your_secret_key"; // Insert your custom key
const encryptedData = temcrypt.encrypt({
dataString: dataToEncrypt,
mainKey: mainKey
});
console.log(encryptedData);
解密字符串
const encryptedData = "..."; // Encrypted data obtained from the encryption process
const mainKey = "your_secret_key";
const decryptedData = temcrypt.decrypt({
dataString: encryptedData,
mainKey: mainKey
});
console.log(decryptedData);
加密文件:
要使用 temcrypt 加密文件,您可以使用encrypt
带有dataFiles
参数的函数。以下是如何加密文件并获取加密结果的示例:
const temcrypt = require("temcrypt");
const filePath = "path/test.txt";
const mainKey = "your_secret_key";
const result = temcrypt.encrypt({
dataFiles: filePath,
mainKey: mainKey,
extraBytes: 128 // Optional: Add 128 extra bytes
});
console.log(result);
在此示例中,替换'test.txt'
为要加密的文件的实际路径,并将其设置'your_secret_key'
为加密的主密钥。该result
对象将包含加密详细信息,包括唯一哈希、主密钥、时间密钥和加密文件的文件路径。
解密文件:
要解密之前使用 temcrypt 加密的文件,您可以使用decrypt
带有dataFiles
参数的函数。以下是如何解密文件并获取解密结果的示例:
const temcrypt = require("temcrypt");
const filePath = "path/test.txt.trypt";
const mainKey = "your_secret_key";
const result = temcrypt.decrypt({
dataFiles: filePath,
mainKey: mainKey
});
console.log(result);
本例中替换'path/test.txt.trypt'
为加密文件的实际路径,并设置'your_secret_key'
为解密的主密钥。如果成功,结果对象将包含解密状态和解密数据。
请记住在加密期间提供正确的主密钥,以便在加密文件的同一时间和分钟成功解密文件。如果主密钥错误或文件被篡改或时间错误,则解密状态为 ,false
解密后的数据将不可用。
实用工具
temcrypt 提供utils
执行加密和解密之外的其他操作的函数。这些实用功能旨在增强功能性和可用性。
功能列表:
- changeKey:更改您的加密主密钥
- check:检查加密是否属于temcrypt
- verify:检查哈希是否与加密输出的合法性匹配。
下面,您可以看到详细信息以及如何实现其用途。
更新主键:
该changeKey
实用程序功能允许您更改用于加密数据的主密钥,同时保持加密数据的完整性。当您想要增强加密数据的安全性或定期更新 mainKey 时,这非常有用。
参数
dataFiles
(可选):使用 temcrypt 加密的文件的路径。dataString
(可选):使用 temcrypt 生成的加密字符串。mainKey
( string ): 当前用于加密数据的主密钥。newKey
( string ):将替换当前 mainKey 的新 mainKey。
const temcrypt = require("temcrypt");
const filePath = "test.txt.trypt";
const currentMainKey = "my_recent_secret_key";
const newMainKey = "new_recent_secret_key";
// Update mainKey for the encrypted file
const result = temcrypt.utils({
changeKey: {
dataFiles: filePath,
mainKey: currentMainKey,
newKey: newMainKey
}
});
console.log(result.message);
检查数据完整性:
该check
实用程序功能允许您验证使用 temcrypt 加密的数据的完整性。它检查文件或字符串是否是有效的 temcrypt 加密数据。
参数
dataFiles
(可选):要检查的文件的路径。dataString
(可选):您要检查的加密字符串。
const temcrypt = require("temcrypt");
const filePath = "test.txt.trypt";
const encryptedString = "..."; // Encrypted string generated by temcrypt
// Check the integrity of the encrypted File
const result = temcrypt.utils({
check: {
dataFiles: filePath
}
});
console.log(result.message);
// Check the integrity of the encrypted String
const result2 = temcrypt.utils({
check: {
dataString: encryptedString
}
});
console.log(result2.message);
验证哈希:
该verify
实用程序函数允许您使用哈希值验证加密数据的完整性。检查加密数据输出是否与提供的哈希值匹配。
参数
hash
( string ):要验证的哈希值。dataFiles
(可选):要验证其哈希值的文件的路径。dataString
(可选):您要验证其哈希值的加密字符串。
const temcrypt = require("temcrypt");
const filePath = "test.txt.trypt";
const hashToVerify = "..."; // The hash value to verify
// Verify the hash of the encrypted File
const result = temcrypt.utils({
verify: {
hash: hashToVerify,
dataFiles: filePath
}
});
console.log(result.message);
// Verify the hash of the encrypted String
const result2 = temcrypt.utils({
verify: {
hash: hashToVerify,
dataString: encryptedString
}
});
console.log(result2.message);
错误代码
下表列出了 temcrypt 用于指示各种错误情况的重要错误代码及其相应的错误消息。
代码 | 错误信息 | 描述 |
---|---|---|
第420章 | 超过解密时间限制 | 解密过程花费的时间超过了允许的时间限制。 |
第444章 | 解密失败 | 解密过程遇到错误。 |
第777章 | 未提供数据 | 没有提供该操作的数据。 |
第859章 | temcrypt 加密字符串无效 | 提供的字符串不是有效的 temcrypt 加密字符串。 |
项目地址
temcrypt:【GitHub】
暂无评论内容