Constructor
# new SimpleCrypto(secret)
Represent a SimpleCrypto instance
Parameters:
Name | Type | Description |
---|---|---|
secret |
string | The secret key for cryptographic process. |
Classes
Members
Methods
# static generateRandom(length, expectsWordArray) → {string|WordArray}
Generate Random
Generate a random string or WordArray.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
length |
number | 128 | The length of random to be generated. |
expectsWordArray |
boolean | false | Set to true to return WordArray instance. Default is false and return a string. |
- Since:
- 2017.10.16
- See:
-
- WordArray
Returns a random string or WordArray.
string
|
WordArray
# static generateRandomString(length) → {string|WordArray}
Generate Random String
Generate a random string
Parameters:
Name | Type | Default | Description |
---|---|---|---|
length |
number | 128 | The length of random to be generated. |
- Since:
- 2020.05.09
- See:
-
- WordArray
Returns a random string.
string
|
WordArray
# static generateRandomWordArray(length) → {string|WordArray}
Generate Random Word Array
Generate a random WordArray.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
length |
number | 128 | The length of random to be generated. |
- Since:
- 2020.05.09
- See:
-
- WordArray
Returns a random WordArray.
string
|
WordArray
# append(data) → {SimpleCrypto}
Append
Append the data to be encrypted or decrypted.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | string | number | boolean | Data to be encrypted or decrypted. |
- Since:
- 2020.05.09
Current SimpleCrypto instance.
# decryptObject(cipher) → {string}
Decrypt Object
Decrypt a encrypted string and try to convert it back to object.
Parameters:
Name | Type | Description |
---|---|---|
cipher |
string | The encrypted string of the data. |
- Since:
- 2017.10.16
- Deprecated:
- Since version 2.0.0, use decrypt(cipher: CipherText) instead.
- See:
-
- decrypt
The decrypted data of the encrypted string in the form
of object.
string
# encryptObject(object) → {string}
Encrypt Object
Encrypt an object.
Parameters:
Name | Type | Description |
---|---|---|
object |
object | The object to be encrypted. |
- Since:
- 2017.10.16
- Deprecated:
- Since version 2.0.0, use encrypt(data: PlainData) instead.
- See:
-
- encrypt
The encrypted string of the object.
string
# setEncoder(encoder) → {SimpleCrypto}
Set Encoder
Change the default encoding type for the decryption process.
Parameters:
Name | Type | Description |
---|---|---|
encoder |
Encoder | The new Encoder object. |
- Since:
- 2020.05.09
Current SimpleCrypto instance.
# setSecret(secret) → {SimpleCrypto}
Set Secret
Change the secret key by setting a new one. By changing the secret key,
any encrypted string that encrypted by previous secret key will not be
able to decrypted, unless the secret key is set to the one used to
encrypt the data.
Parameters:
Name | Type | Description |
---|---|---|
secret |
string | The new secret key as string. |
- Since:
- 2017.10.16
Current SimpleCrypto instance.
# update(data) → {SimpleCrypto}
Update
Change data to be encrypted or decrypted.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | string | number | boolean | Data to be encrypted or decrypted. |
- Since:
- 2020.05.09
Current SimpleCrypto instance.