implemented first of the fallback crypto functions
This commit is contained in:
		
							parent
							
								
									6ec723ec1f
								
							
						
					
					
						commit
						e8e9b961a4
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | node_modules/ | ||||||
							
								
								
									
										32
									
								
								browserify/crypto-index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								browserify/crypto-index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | ;(function () { | ||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  |   var createHash = require('create-hash'); | ||||||
|  |   var pbkdf2 = require('pbkdf2'); | ||||||
|  |   var aes = require('browserify-aes'); | ||||||
|  | 
 | ||||||
|  |   exports.sha256 = function (buf) { | ||||||
|  |     var hash = createHash('sha256'); | ||||||
|  |     hash.update(buf); | ||||||
|  |     hash.end(); | ||||||
|  |     return Promise.resolve(hash.read()); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   exports.encrypt = function (data, password, salt, iv) { | ||||||
|  |     // Derived AES key is 128 bit, and the function takes a size in bytes.
 | ||||||
|  |     var aesKey = pbkdf2.pbkdf2Sync(password, Buffer(salt), 8192, 16, 'sha256'); | ||||||
|  |     var cipher = aes.createCipheriv('aes-128-gcm', aesKey, Buffer(iv)); | ||||||
|  |     var result = Buffer.concat([cipher.update(Buffer(data)), cipher.final(), cipher.getAuthTag()]); | ||||||
|  |     return Promise.resolve(result); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   exports.decrypt = function (data, password, salt, iv) { | ||||||
|  |     var aesKey = pbkdf2.pbkdf2Sync(password, Buffer(salt), 8192, 16, 'sha256'); | ||||||
|  |     var decipher = aes.createDecipheriv('aes-128-gcm', aesKey, Buffer(iv)); | ||||||
|  | 
 | ||||||
|  |     decipher.setAuthTag(Buffer(data.slice(-16))); | ||||||
|  |     var result = Buffer.concat([decipher.update(Buffer(data.slice(0, -16))), decipher.final()]); | ||||||
|  |     return Promise.resolve(result); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  | }()); | ||||||
							
								
								
									
										21
									
								
								gulpfile.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								gulpfile.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | ;(function () { | ||||||
|  |   'use strict'; | ||||||
|  | 
 | ||||||
|  |   var gulp = require('gulp'); | ||||||
|  |   var browserify = require('browserify'); | ||||||
|  |   var source = require('vinyl-source-stream'); | ||||||
|  |   var streamify = require('gulp-streamify'); | ||||||
|  |   var uglify = require('gulp-uglify'); | ||||||
|  |   var rename = require('gulp-rename'); | ||||||
|  | 
 | ||||||
|  |   gulp.task('default', function () { | ||||||
|  |     return browserify('./browserify/crypto-index.js', {standalone: 'OAUTH3_crypto'}).bundle() | ||||||
|  |       .pipe(source('browserify/crypto-index.js')) | ||||||
|  |       .pipe(rename('oauth3.crypto.js')) | ||||||
|  |       .pipe(gulp.dest('./')) | ||||||
|  |       .pipe(streamify(uglify())) | ||||||
|  |       .pipe(rename('oauth3.crypto.min.js')) | ||||||
|  |       .pipe(gulp.dest('./')) | ||||||
|  |       ; | ||||||
|  |   }); | ||||||
|  | }()); | ||||||
							
								
								
									
										23
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | { | ||||||
|  |   "name": "oauth3", | ||||||
|  |   "respository": { | ||||||
|  |     "type": "git", | ||||||
|  |     "url": "git+ssh://git@git.daplie.com:Daplie/oauth3.js.git" | ||||||
|  |   }, | ||||||
|  |   "scripts": { | ||||||
|  |     "install": "./node_modules/.bin/gulp" | ||||||
|  |   }, | ||||||
|  |   "devDependencies": { | ||||||
|  |     "atob": "^2.0.3", | ||||||
|  |     "browserify": "^14.1.0", | ||||||
|  |     "browserify-aes": "^1.0.6", | ||||||
|  |     "btoa": "^1.1.2", | ||||||
|  |     "gulp": "^3.9.1", | ||||||
|  |     "gulp-cli": "^1.2.2", | ||||||
|  |     "gulp-rename": "^1.2.2", | ||||||
|  |     "gulp-streamify": "^1.0.2", | ||||||
|  |     "gulp-uglify": "^2.1.0", | ||||||
|  |     "pbkdf2": "^3.0.9", | ||||||
|  |     "vinyl-source-stream": "^1.1.0" | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user