1
1
import { Command , flags } from '@oclif/command'
2
2
import * as CryptoJS from 'crypto-js'
3
- import { JsonFormatter } from 'tslint/lib/formatters'
4
-
5
- import Utilities from '../utilities/Utilities'
6
3
import Logger from '../utilities/Logger'
7
4
import Hash from './hash'
8
5
9
6
export default class Crypto extends Command {
10
7
static ENCRYPTION = 'encryption'
11
8
static DECRYPTION = 'decryption'
12
-
13
9
static description = 'Encryption and Decryption functionality'
14
10
static flags = {
15
11
help : flags . help ( { char : 'h' } ) ,
@@ -23,7 +19,6 @@ export default class Crypto extends Command {
23
19
}
24
20
25
21
static args = [ { name : 'string' } ]
26
-
27
22
//need INPUT_STRING, TYPE_OF_CRYPTO , KEY, MODE
28
23
async run ( ) {
29
24
const { args, flags} = this . parse ( Crypto )
@@ -33,35 +28,25 @@ export default class Crypto extends Command {
33
28
34
29
this . checkParameters ( flags , args )
35
30
flags . encryption ? this . Encrypt ( flags , args ) : this . Decrypt ( flags , args )
36
-
37
31
}
38
32
39
33
private Encrypt ( flags : any , args :any ) {
40
-
41
34
let crypto = this . getCryptoType ( args . type )
42
-
43
35
Logger . info ( this , `Encryption: ${ flags . encryption . toUpperCase ( ) } ` )
44
-
45
36
// @ts -ignore // as crypto will never be undefined and reach here
46
37
let encrypted : string = crypto . encrypt ( args . string , flags . key , {
47
38
mode : this . getCryptoMode ( this , flags )
48
39
} ) . toString ( )
49
-
50
- //always add input to args
51
-
52
40
Logger . success ( this , `${ encrypted } ` )
53
41
}
54
42
55
43
private Decrypt ( flags : any , args : any ) {
56
44
let crypto = this . getCryptoType ( args . type )
57
-
58
45
Logger . info ( this , `Decryption: ${ flags . decryption . toUpperCase ( ) } ` )
59
-
60
46
// @ts -ignore // as crypto will never be undefined and reach here
61
47
let decrypted : string = crypto . decrypt ( args . string , flags . key , {
62
48
mode : this . getCryptoMode ( this , flags )
63
49
} ) . toString ( CryptoJS . enc . Utf8 )
64
-
65
50
Logger . success ( this , `${ decrypted } ` )
66
51
}
67
52
@@ -83,7 +68,6 @@ export default class Crypto extends Command {
83
68
Logger . error ( this , 'Invalid or Unsupported Encryption/Decryption type' )
84
69
return undefined // will never reach here
85
70
}
86
-
87
71
}
88
72
89
73
// to check required parameters passed or not
0 commit comments