You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					17 lines
				
				415 B
			
		
		
			
		
	
	
					17 lines
				
				415 B
			| 
								 
											4 years ago
										 
									 | 
							
								var xor = require('buffer-xor')
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function getBlock (self) {
							 | 
						||
| 
								 | 
							
								  self._prev = self._cipher.encryptBlock(self._prev)
							 | 
						||
| 
								 | 
							
								  return self._prev
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								exports.encrypt = function (self, chunk) {
							 | 
						||
| 
								 | 
							
								  while (self._cache.length < chunk.length) {
							 | 
						||
| 
								 | 
							
								    self._cache = Buffer.concat([self._cache, getBlock(self)])
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  var pad = self._cache.slice(0, chunk.length)
							 | 
						||
| 
								 | 
							
								  self._cache = self._cache.slice(chunk.length)
							 | 
						||
| 
								 | 
							
								  return xor(chunk, pad)
							 | 
						||
| 
								 | 
							
								}
							 |