Class
class HMAC
public class HMAC <: Digest {
public init(key: Array<Byte>, digest: () -> Digest)
public init(key: Array<Byte>, algorithm: HashType)
}
Description: Provides implementation functions of the HMAC algorithm. The currently supported digest algorithms include MD5, SHA1, SHA224, SHA256, SHA384, SHA512, and SM3.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the information block length (in bytes) of the hash algorithm selected by HMAC.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the digest information length (in bytes) of the hash algorithm selected by HMAC.
Type: Int64
init(Array<Byte>, () -> Digest)
public init(key: Array<Byte>, digest: () -> Digest)
Description: Indicates a constructor used to create an HMAC object.
Parameters:
- key: Array<Byte>: key. It is recommended that this parameter be greater than or equal to the digest length of the selected hash algorithm.
- digest: () -> Digest: hash algorithm
Throws:
- CryptoException: When the key value is null, this exception is thrown.
init(Array<Byte>, HashType)
public init(key: Array<Byte>, algorithm: HashType)
Description: Indicates a constructor used to create an HMAC object.
Parameters:
- key: Array<Byte>: key. It is recommended that this parameter be greater than or equal to the digest length of the selected hash algorithm.
- algorithm: HashType: hash algorithm.
Throws:
- CryptoException: When the key value is null, this exception is thrown.
func equal(Array<Byte>, Array<Byte>)
public static func equal(mac1: Array<Byte>, mac2: Array<Byte>): Bool
Description: Checks whether two message digests are equal and without disclosing the comparison time. That is, the traditional short-circuit principle is not used for the comparison to prevent timing attacks.
Parameters:
- mac1: Array<Byte>: one information digest sequence
- mac2: Array<Byte>: the other information digest sequence
Returns:
- Bool: whether the information digests are equal; true: yes, false: no
func finish()
public func finish(): Array<Byte>
Description: Returns the generated message digest value. Note that digest calculation cannot be performed after finish is called. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets an HMAC object to the initial state and clears the HMAC context.
Throws:
- CryptoException: When the resetting fails due to an internal error, this exception is thrown.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates an HMAC object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When buffer is empty or finish has been called to generate an information digest, this exception is thrown.
class MD5
public class MD5 <: Digest {
public init()
}
Description: Provides implementation functions of the MD5 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of an MD5 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of an MD5 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create an MD5 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated MD5 value. Note that the MD5 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets an MD5 object to the initial state and clears the MD5 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates an MD5 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SHA1
public class SHA1 <: Digest {
public init()
}
Description: Provides implementation functions of the SHA1 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of a SHA1 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of a SHA1 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create a SHA1 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SHA1 value. Note that the SHA1 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets a SHA1 object to the initial state and clears the SHA1 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates a SHA1 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SHA224
public class SHA224 <: Digest {
public init()
}
Description: Provides implementation functions of the SHA224 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of a SHA224 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of a SHA224 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create a SHA224 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SHA224 value. Note that the SHA224 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets a SHA224 object to the initial state and clears the SHA224 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates a SHA224 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SHA256
public class SHA256 <: Digest {
public init()
}
Description: Provides implementation functions of the SHA256 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of a SHA256 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of a SHA256 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create a SHA256 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SHA256 value. Note that the SHA256 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets a SHA256 object to the initial state and clears the SHA256 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates a SHA256 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SHA384
public class SHA384 <: Digest {
public init()
}
Description: Provides implementation functions of the SHA384 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of a SHA384 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of a SHA384 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create a SHA384 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SHA384 value. Note that the SHA384 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets a SHA384 object to the initial state and clears the SHA384 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates a SHA384 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SHA512
public class SHA512 <: Digest {
public init()
}
Description: Provides implementation functions of the SHA512 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of a SHA512 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of a SHA512 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create a SHA512 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SHA512 value. Note that the SHA512 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets a SHA512 object to the initial state and clears the SHA512 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates a SHA512 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
class SM3
public class SM3 <: Digest {
public init()
}
Description: Provides implementation functions of the SM3 algorithm.
Parent Type:
prop blockSize
public prop blockSize: Int64
Description: Obtains the length (in bytes) of an SM3 information block.
Type: Int64
prop size
public prop size: Int64
Description: Obtains the length (in bytes) of an SM3 digest information.
Type: Int64
init()
public init()
Description: Indicates a constructor without parameters used to create an SM3 object.
func finish()
public func finish(): Array<Byte>
Description: Returns the generated SM3 value. Note that the SM3 context changes after finish is called. After finish is called, digest calculation cannot be performed. If digest calculation needs to be performed again, the context needs to be reset.
Returns:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.
func reset()
public func reset(): Unit
Description: Resets an SM3 object to the initial state and clears the SM3 context.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Updates an SM3 object using a given buffer. An object can be updated more than once before finish is called.
Parameters:
Throws:
- CryptoException: When finish is called again to perform digest calculation without context reset, this exception is thrown.