Skip to content

Commit 88c5b70

Browse files
committed
[CRYPTO]: closes #13
Signed-off-by: ashish <[email protected]>
1 parent fef6654 commit 88c5b70

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/commands/hash.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Command, flags} from '@oclif/command'
2+
import * as CryptoJS from 'crypto-js'
23
// @ts-ignore
3-
import * as Hashes from 'jshashes'
44

55
import Logger from '../utilities/logger'
66
import Utilities from '../utilities/utilities'
@@ -12,7 +12,7 @@ export default class Hash extends Command {
1212
static flags = {
1313
help: flags.help({char: 'h'}),
1414
// -t , --type for hashing
15-
type: flags.string({char: 't' , description: 'type of hash [SHA1(default),MD5,SHA256,SHA512,RMD160]'}),
15+
type: flags.string({char: 't' , description: 'type of hash [SHA1(default), MD5, SHA256, SHA512, RMD160 or RIPEMD160]'}),
1616
string: flags.string({char: 's' , description: 'string to be hashed'}),
1717
file: flags.string({char: 'f' , description: 'file to be hashed'}),
1818
}
@@ -52,22 +52,41 @@ export default class Hash extends Command {
5252

5353
private calculateHash(flags: any, args: any) {
5454
const hashObject = this.getHashObject(flags)
55-
let hashed: string = hashObject.hex(args.string)
55+
// @ts-ignore
56+
let hashed: string = hashObject(args.string)
5657
Logger.success(this, `[${flags.type.toUpperCase()}] ${hashed}`)
5758
}
5859

60+
// import * as Hashes from 'jshashes'
61+
// private getHashObjectBCK(flags: any) {
62+
// switch (flags.type.toUpperCase()) {
63+
// case 'SHA1':
64+
// return new Hashes.SHA1()
65+
// case 'SHA256':
66+
// return new Hashes.SHA256()
67+
// case 'SHA512':
68+
// return new Hashes.SHA512()
69+
// case 'MD5':
70+
// return new Hashes.MD5()
71+
// case 'RMD160':
72+
// return new Hashes.RMD160()
73+
// default:
74+
// Logger.error(this, 'Invalid Or Unsupported hash type')
75+
// }
76+
// }
77+
5978
private getHashObject(flags: any) {
6079
switch (flags.type.toUpperCase()) {
6180
case 'SHA1':
62-
return new Hashes.SHA1()
81+
return CryptoJS.SHA1
6382
case 'SHA256':
64-
return new Hashes.SHA256()
83+
return CryptoJS.SHA256
6584
case 'SHA512':
66-
return new Hashes.SHA512()
85+
return CryptoJS.SHA512
6786
case 'MD5':
68-
return new Hashes.MD5()
69-
case 'RMD160':
70-
return new Hashes.RMD160()
87+
return CryptoJS.MD5
88+
case 'RMD160': case 'RIPEMD160':
89+
return CryptoJS.RIPEMD160
7190
default:
7291
Logger.error(this, 'Invalid Or Unsupported hash type')
7392
}

src/utilities/utilities.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import * as fs from 'fs'
33

44
import Logger from './logger'
5-
65
// tslint:disable-next-line:no-unnecessary-class
76
export default class Utilities {
87
public static getStringFromFile(thisRef: any, filePath: string) {

0 commit comments

Comments
 (0)