Encrypt
Last updated
Was this helpful?
Last updated
Was this helpful?
Encrypts an object using the specified algorithm and key
object
any
false
The object to encrypt. If the object is not a string or binary data, the object must implement the java.io.Serializable interface
key
string
true
The string representation of the secret key to use for encryption ( see generateSecretKey() )
algorithm
string
false
The algorithm to use for encryption. Default is AES
encoding
string
false
The encoding type to use for encoding the encrypted data. Default is Base64
UU
IVorSalt
any
false
The initialization vector or salt to use for encryption.
iterations
integer
false
The number of iterations to use for encryption. Default is 1000
1000
precise
boolean
false
If set to true, the string and key will be validated before encryption to ensure conformity to the algorithm. Default is false
true
The key must be generated using the generateSecretKey("AES") function.
Result: keciULin7bxOWvN/BOarWw==
By default encrypt() uses the Electronic Code Book (ECB) mode for encryption. For increased security you should specify the mode and padding to use. In this example we will use CBC mode and PKCS5Padding. The value of the encrypted string will be different every time it runs because the IV is generated at random.