11import { Command , flags } from '@oclif/command'
2+ import * as CryptoJS from 'crypto-js'
23// @ts -ignore
3- import * as Hashes from 'jshashes'
44
55import Logger from '../utilities/logger'
66import 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 }
0 commit comments