md5-node-cg-lib
v0.0.11
Published
Library to create MD5 ids
Downloads
6
Maintainers
Readme
md5-node-cg-lib
1. Introduction
This library allows us to create an id md5 or, the creation of this md5 can with information in any encoding or any encoding and convert it to utf8, in the same way this library allows us to validate the integrity of the information by validating the id md5 with one new from the information that you want to validate
2. Library usage
The library can be installed from npm page with the next:
npm install md5-node-cg-lib
, npm i md5-node-cg-lib
or yarn install md5-node-cg-lib
2.1 Library Methods
Method getMd5ID
This method creates the md5 id, without validations, only create id with any parameter
Example:
const data = getMd5ID("Hello World");
//Result will be id md5
b10a8db164e0754105b7a99be72e3fe5
Method createSum
This method creates the md5 id with the method getMd5ID, but it validates data before send to the method getMd5ID, this method receives two arguments, first is the data to create id in any encoding, and the second parameter is flag, the flag is optional, the flag is value to the operation in components like sftp, ftp, ftps, and amazon aws, these components can create id, but only with the flag GETFILE, other flags are not valid.
Examples:
//Creating md5 id without flag
console.log(createSum("ZWZyZnI="))
console.log(createSum("ZWZyZnI"))
//Result same md5 id
361df7e337886f73e12e96dc186c78ec
361df7e337886f73e12e96dc186c78ec
//Example using flag
console.log(JSON.stringify(createSum("ZWZyZnI", flags.CREATEDIRECTORY)))
console.log(createSum("ZWZyZnI=", flags.GETFILE))
//Result, if flag is not valid, the output will be a string empty
""
361df7e337886f73e12e96dc186c78ec
Method checkSumMD5
This method check integrity of data, receives two arguments the first is msg and second is cfg, these parameters are received from the components, the validation is with property md5sum and content.
- If msg and cfg not contains property md5sum the result is true because we don’t have any to validate.
- If msg or cfg contains md5sum but not contains property content, result will be false, because we need property content to validate integrity.
- If msg or cfg contains both properties ‘md5sum’ and ‘content’, we can validate integrity the data creating md5id with property content with encoding utf8 and comparing this id with the id from the property md5sum, if both ids are the same the result will be can true, if not result will be can false.
Example:
const data = {
content: 'ZWZyZnI=',
md5sum: '361df7e337886f73e12e96dc186c78ec'
};
console.log('Result is:', checkSumMD5({data}, {}));
//The result is Boolean
Result is: true