public class Security
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static org.apache.commons.logging.Log |
log
encryption settings
|
Constructor and Description |
---|
Security() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decrypt(java.lang.String text)
decrypt text using stored initVector and securityKey
|
static java.lang.String |
decrypt(java.lang.String text,
byte[] initVector,
byte[] secretKey)
decrypt text to a string with specific initVector and secretKey; rarely used except in
testing and where specifically necessary
|
static java.lang.String |
encodeString(java.lang.String strToEncode)
This method will hash
strToEncode using the preferred algorithm. |
static java.lang.String |
encrypt(java.lang.String text)
encrypt text using stored initVector and securityKey
|
static java.lang.String |
encrypt(java.lang.String text,
byte[] initVector,
byte[] secretKey)
encrypt text to a string with specific initVector and secretKey; rarely used except in
testing and where specifically necessary
|
static byte[] |
generateNewInitVector()
generate a new cipher initialization vector; should only be called once in order to not
invalidate all encrypted data
|
static byte[] |
generateNewSecretKey()
generate a new secret key; should only be called once in order to not invalidate all
encrypted data
|
static java.lang.String |
getRandomToken()
This method will generate a random string
|
static byte[] |
getSavedInitVector()
retrieve the stored init vector from runtime properties
|
static byte[] |
getSavedSecretKey()
retrieve the secret key from runtime properties
|
static boolean |
hashMatches(java.lang.String hashedPassword,
java.lang.String passwordToHash)
Compare the given hash and the given string-to-hash to see if they are equal.
|
public static boolean hashMatches(java.lang.String hashedPassword, java.lang.String passwordToHash)
hashedPassword
- a stored password that has been hashed previouslypasswordToHash
- a string to encode/hash and compare to hashedPasswordpublic static java.lang.String encodeString(java.lang.String strToEncode) throws APIException
strToEncode
using the preferred algorithm. Currently,
OpenMRS's preferred algorithm is hard coded to be SHA-512.strToEncode
- string to encodeAPIException
public static java.lang.String getRandomToken() throws APIException
APIException
public static java.lang.String encrypt(java.lang.String text, byte[] initVector, byte[] secretKey)
text
- string to be encryptedinitVector
- custom init vector byte arraysecretKey
- custom secret key byte arrayencrypt(String)
public static java.lang.String encrypt(java.lang.String text)
text
- public static java.lang.String decrypt(java.lang.String text, byte[] initVector, byte[] secretKey)
text
- text to be decryptedinitVector
- custom init vector byte arraysecretKey
- custom secret key byte arraydecrypt(String)
public static java.lang.String decrypt(java.lang.String text)
text
- text to be decryptedpublic static byte[] getSavedInitVector()
public static byte[] generateNewInitVector()
public static byte[] getSavedSecretKey()
public static byte[] generateNewSecretKey()
Copyright © 2018 OpenMRS Inc.. All Rights Reserved.