Common front end byte code (base64, hex, utf8) and its conversion

/ * 
* Byte transcoding 
* First need to Grade array system (an ArrayBuffer) 
* before converting the character code corresponding to 
* distal common encoding: 
* Base64: is converted to a binary string, bytes per 6 into a particular string (a-Za-z0-9 / + =). 
* Hex: binary 8-byte hexadecimal into two corresponding string 
* * / 

// UTF8 into Base64 / hex 
the let Buffer.from Output = ( 'UTF8 string', 'utf8 ') 
the console.log (output.toString (' Base64 ')) 
the console.log (output.toString (' hex ')) 


// Base64 / hex Switch UTF8 
Output = Buffer.from (' 75746638e79a84e5ad97e7aca6e4b8b2 ',' hex ') 
the console.log (output.toString ( 'UTF8')) 
Output = Buffer.from ( '+ espuS4sg dXRmOOeahOWtl ==', 'Base64') 
the console.log (output.toString ( 'UTF8')) 


// read the file transfer encoding the 
input = fs.readFileSync ( 'test. 
console.
console.log(input)
input = fs.readFileSync('test.txt', 'base64')
console.log(input)
input = fs.readFileSync('test.txt', 'hex')
console.log(input)

  

 

/ * 
* It should be noted encryption 
Encrypted Data Type: Buffer or string (hex / Base64 / UTF8) 
* argument to parameter: vi - filled 
* parameters into parameters: mode - Mode 
* parameters into parameters: padding - filling type 
encryption type * output: Buffer or string (hex / Base64 / UTF8) 
* * /

  

Guess you like

Origin www.cnblogs.com/jiebba/p/12023652.html