11import { Command , flags } from '@oclif/command'
22import * as CryptoJS from 'crypto-js'
3- import { JsonFormatter } from 'tslint/lib/formatters'
4-
5- import Utilities from '../utilities/Utilities'
63import Logger from '../utilities/Logger'
74import Hash from './hash'
85
96export default class Crypto extends Command {
107 static ENCRYPTION = 'encryption'
118 static DECRYPTION = 'decryption'
12-
139 static description = 'Encryption and Decryption functionality'
1410 static flags = {
1511 help : flags . help ( { char : 'h' } ) ,
@@ -23,7 +19,6 @@ export default class Crypto extends Command {
2319 }
2420
2521 static args = [ { name : 'string' } ]
26-
2722 //need INPUT_STRING, TYPE_OF_CRYPTO , KEY, MODE
2823 async run ( ) {
2924 const { args, flags} = this . parse ( Crypto )
@@ -33,35 +28,25 @@ export default class Crypto extends Command {
3328
3429 this . checkParameters ( flags , args )
3530 flags . encryption ? this . Encrypt ( flags , args ) : this . Decrypt ( flags , args )
36-
3731 }
3832
3933 private Encrypt ( flags : any , args :any ) {
40-
4134 let crypto = this . getCryptoType ( args . type )
42-
4335 Logger . info ( this , `Encryption: ${ flags . encryption . toUpperCase ( ) } ` )
44-
4536 // @ts -ignore // as crypto will never be undefined and reach here
4637 let encrypted : string = crypto . encrypt ( args . string , flags . key , {
4738 mode : this . getCryptoMode ( this , flags )
4839 } ) . toString ( )
49-
50- //always add input to args
51-
5240 Logger . success ( this , `${ encrypted } ` )
5341 }
5442
5543 private Decrypt ( flags : any , args : any ) {
5644 let crypto = this . getCryptoType ( args . type )
57-
5845 Logger . info ( this , `Decryption: ${ flags . decryption . toUpperCase ( ) } ` )
59-
6046 // @ts -ignore // as crypto will never be undefined and reach here
6147 let decrypted : string = crypto . decrypt ( args . string , flags . key , {
6248 mode : this . getCryptoMode ( this , flags )
6349 } ) . toString ( CryptoJS . enc . Utf8 )
64-
6550 Logger . success ( this , `${ decrypted } ` )
6651 }
6752
@@ -83,7 +68,6 @@ export default class Crypto extends Command {
8368 Logger . error ( this , 'Invalid or Unsupported Encryption/Decryption type' )
8469 return undefined // will never reach here
8570 }
86-
8771 }
8872
8973 // to check required parameters passed or not
0 commit comments