OScript API/Built-in Package Index

Class: Security

The Security package provides encryption, decryption and hashing functions. The major functionalities offered in the Security Package are the following:

Deprecated hash and encryption family types will be removed from Content Server 22.2. Any solution using these types should immediately remove usage and switch to a more secure algorithm provided by the system.

Class Attributes

128 bit AES in CBC mode.

128 bit AES in 128 bit CFB mode.

128 bit AES in 8 bit CFB mode.

128 bit AES in ECB mode.

128 bit AES in 128 bit OFB mode.

192 bit AES in CBC mode.

192 bit AES in 128 bit CFB mode.

192 bit AES in 8 bit CFB mode.

192 bit AES in ECB mode.

192 bit AES in 128 bit OFB mode.

256 bit AES in CBC mode.

256 bit AES in 128 CFB mode.

256 bit AES in 8 bit CFB mode.

256 bit AES in ECB mode.

256 bit AES in 128 OFB mode.

128 bit blowfish in CBC mode.

128 bit blowfish in 64 bit CFB mode.

128 bit blowfish in ECB mode.

128 bit blowfish in 64 bit OFB mode.

CAST5_CBC Deprecated

128 bit CAST5 in CBC mode.

CAST5_CFB64 Deprecated

128 bit CAST5 in 64 bit CFB mode.

CAST5_ECB Deprecated

128 bit CAST5 in ECB mode.

CAST5_OFB64 Deprecated

128 bit CAST5 in 64 bit OFB mode.

DES_CBC Deprecated

56 bit DES in CBC mode.

DES_CFB64 Deprecated

56 bit DES in 64 bit CFB mode.

DES_CFB8 Deprecated

56 bit DES in 8 bit CFB mode.

DES_ECB Deprecated

56 bit DES in ECB mode.

168 bit 3DES in CBC mode.

168 bit 3DES in 64 bit CFB mode.

168 bit 3DES in ECB mode.

168 bit 3DES in 64 bit OFB mode.

DES_EDE_CBC Deprecated

112 bit 2 key triple DES in ECB mode.

DES_EDE_CFB64 Deprecated

112 bit 2 key triple DES in 64 bit CFB mode.

DES_EDE_ECB Deprecated

112 bit 2 key triple DES in ECB mode.

DES_EDE_OFB64 Deprecated

112 bit 2 key triple DES in 64 bit OFB mode.

DES_OFB64 Deprecated

56 bit DES in 64 bit OFB mode.

DESX_CBC Deprecated

56 bit DESX in CBC mode.

MD2 Deprecated

128 bit

MD4 Deprecated

128 bit

128 bit

RC2_40_CBC Deprecated

40 bit RC2 in CBC mode.

64 bit RC2 in CBC mode.

RC2_CBC Deprecated

128 bit RC2 in CBC mode.

RC2_CFB64 Deprecated

128 bit RC2 in CFB mode.

RC2_ECB Deprecated

128 bit RC2 in ECB mode.

RC2_OFB64 Deprecated

128 bit RC2 in OFB mode.

RC4 Deprecated

128 bit RC4.

RC4_40 Deprecated

40 bit RC4.

RIPEMD160 Deprecated

160 bit

160 bit

224 bit

256 bit SHA-2 hash.

384 bit SHA-2 hash.

512 bit SHA-2 hash.

Class Methods

CheckPassword( String password, String cryptPassword )

Check the password against the encrypted password.

ConvertLegacyHash( String pwdOldHash )

Converts an old password using the SHA512 algorithm.

Decrypt( String value, String key, Integer encryptionType )

Decrypts 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Value should a base64 encoded string of bytes

DecryptBytes( Bytes value, String key, Integer encryptionType )

Decrypts the Bytes 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Returns a string.

Encrypt( String value, String key, Integer encryptionType )

Encrypts 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Returns a base64 encoded string of bytes

EncryptBytes( String value, String key, Integer encryptionType )

Encrypts the String 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Returns a Bytes object

Hash( String value, Integer hashType )

Hashes 'value' with the algorithm specified, returning a hex-encoded string.

HashFile( Dynamic theFile, Integer hashType )

Hashes the contents of a file with the algorithm specified, returning a hex-encoded string.

HashPassword( String value )

Hashes 'value' with the SHA512 algorithm, returning a hex-encoded string.

RandomBytes( String text, Integer outputLength )

Generates a random byte string.

Class Attributes

Class Methods

CheckPassword

Boolean CheckPassword( String password,
                       String cryptPassword )

Check the password against the encrypted password. The check is done after hashing 'password' using the SHA512 algorithm.

Parameters

password

the plaintext password.

cryptPassword

the encrypted password.

Returns:

TRUE if matched; FALSE otherwise. Note that FALSE will be returned in case of error.

Example

String plaintextPwd = 'livelink122'

String cryptedPwd = Security.HashPassword(plaintextPwd)

Boolean isSame = Security.CheckPassword( plaintextPwd, cryptedPwd )

Echo( isSame ) // True

ConvertLegacyHash

String ConvertLegacyHash( String pwdOldHash )

Converts an old password using the SHA512 algorithm.

Parameters

pwdOldHash

the password generated with the old hash algorithm.

Returns:

The password encrypted with the SHA512 algorithm. Note that the original input will be returned if it is not a legacy password generated with the old hash algorithm.

Example

String plaintextPwd = 'livelink122'

String legacyPwd = Str.CryptOneWay(plaintextPwd)

Echo( legacyPwd ) //LLZb7NW/T6Y4xXrUPH.7p

String newCryptedPwd = Security.ConvertLegacyHash( legacyPwd )

Echo( newCryptedPwd ) //0$TExd9d7uNDuyCFTaUM43dxrvl|C53yy|7u+3XmgJgdpyRz1KC6rtKTfnOEdzW1F|7FR6kNk9AM4f1tFaYAyGFA==$xySlitgeI2OmQRxfvhuU8Gcz1QgyR2N|u4YU8nXrAF4yAujq1PnYE9IQXTkwm|MH+D|SFClYvr7oqWF5K1AUig==

Decrypt

String Decrypt( String value,
                String key,
                Integer encryptionType )

Decrypts value with key using encryptionType

Parameters

value

String containing the base64 encoded value to be decrypted.

key

String containing the text used to generate the key to decrypt the value with.

encryptionType

Type of encryption to use

Returns:

A hex encoded string of the decrypted value.

DecryptBytes

String DecryptBytes( Bytes value,
                     String key,
                     Integer encryptionType )

Decrypts value with key using encryptionType

Parameters

value

Bytes containing the value to be decrypted.

key

String containing the text used to generate the key to decrypt the value with.

encryptionType

Type of encryption to use

Returns:

A String object of the decrypted value.

Encrypt

String Encrypt( String value,
                String key,
                Integer encryptionType )

Encrypt value with key using encryptionType

Parameters

value

String containing the value to be encrypted.

key

String containing the text used to generate the key to encrypt the value with.

encryptionType

Type of encryption to use

Returns:

A base64 encoded string of the encrypted value.

EncryptBytes

Bytes EncryptBytes( String value,
                    String key,
                    Integer encryptionType )

Encrypts value with key using encryptionType

Parameters

value

String containing the value to be encrypted.

key

String containing the text used to generate the key to encrypt the value with.

encryptionType

Type of encryption to use

Returns:

A Bytes object of the encrypted value.

Hash

String Hash( String value,
             Integer hashType )

Hash value using hashType. Note that Security.SHA is not supported any more.

Parameters

value

String containing the value to be decrypted.

hashType

Type of hash algorithm to use

Returns:

A hex encoded string of the hash; an error if Security.SHA is used.

Example

String text = 'some-string-to-be-hashed'

String hashedValue = Security.Hash( text, Security.SHA256 )

HashFile

String HashFile( Dynamic theFile,
                 Integer hashType )

Hash the contents of theFile using hashType.

Parameters

theFile

Either an open File object, or a String containing the path of a file to be hashed.

hashType

Type of hashing algorithm to use.

Returns:

A hex-encoded string of the hash.

Example

File theFile = File.Open( 'input.txt', File.ReadMode )
String hashedValue = Security.HashFile( theFile, Security.SHA256 )
File.Close( theFile )

HashPassword

String HashPassword( String value )

Hashes 'value' with the SHA512 algorithm, returning a hex-encoded string.

Parameters

value

String containing the value to be decrypted.

Returns:

A hex encoded string of the hash if successful; Empty string otherwise.

Example

String plaintextPwd = 'Livelink1!'

String encryptedPwd = Security.Hash( plaintextPwd )

RandomBytes

Bytes RandomBytes( String text,
                   Integer outputLength )

Generates a random byte string from the input 'text', with length as specified by 'outputLength'.

Parameters

text

The input string based on which the random text will be generated.

outputLength

The length of desired output string.

Returns:

A Bytes object of a random text if successful; Error otherwise.

 Copyright © 2022 OpenText Corporation. All rights reserved.