AHE Lib APIs
A homomorphic encryption library file is provided for integrating the homomorphic encryption function in the client application during development.
The code for importing the library is import "ahe/PSW/api/ahelib".
GenerateKey
- API prototype
func GenerateKey(pwd string) (privKeyStr string, pubKeyStr string, err error)
- Function description
Generating a key pair for homomorphic encryption
- Input
Parameter
Type
Description
Mandatory
pwd
string
Used to encrypt the generated private keychain used for homomorphic encryption. AES-128 is used for the encryption.
The pwd value must contain:
- At least six characters
- At least two types of the following characters:
- Lowercase letters
- Uppercase letters
- Digits
- Spaces or special characters including `~!@#$%^&*()-_=+\|[{}];:'",<.>/?
Yes
- Output
Parameter
Type
Description
privKeyStr
string
Homomorphic private key encrypted using the pwd
pubKeyStr
string
Public keychain for homomorphic encryption
err
error
Error message
- Note
The complexity of keys depends on the actual application scenario. No restrictions need to be imposed on a key used to invoke an underlying library.
Encypt
- API prototype
func Encypt (secretNumStr string, pubKeyStr string) (ciphertext string, err error)
- Function description
Homomorphic encryption
- Input
Parameter
Type
Description
Mandatory
secretNumStr
string
Value to be encrypted. The value must be a positive integer greater than or equal to 0. If the number contains decimal places, the value must be multiplied to eliminate the decimal places.
Yes
pubKeyStr
String
Public key for homomorphic encryption
Yes
- Output
Parameter
Type
Description
ciphertext
string
Encrypted data
err
error
Error message
- Note
None
Decrypt
- API prototype
func Decrypt(ciphertext string, privKeyStr string, pwd string) (plainText *big.Int, err error)
- Function description
Homomorphic decryption
- Input
Parameter
Type
Description
Mandatory
ciphertext
string
Ciphertext to be decrypted
Yes
privKeyStr
string
Private keychain encrypted using the pwd for protection
Yes
pwd
string
Character string used to protect the private key
No
- Output
Parameter
Type
Description
plainText
*big.int
Decrypted data
err
error
Error message
- Note
None
Add
- API prototype
func Add(cipher1, cipher2 string) (cipher string, err error)
- Function description
Additive homomorphic encryption
- Input
Parameter
Type
Description
Mandatory
cipher1
string
Encrypted ciphertext 1
Yes
cipher2
string
Encrypted ciphertext 2
Yes
- Output
Parameter
Type
Description
cipher
string
Combined data
err
error
Error message
- Note
None
InitBalance
- API prototype
func InitBalance(balanceStr string, pubKey string) (string, error)
- Function description
Balance initialization
- Input
Parameter
Type
Description
Mandatory
pubKey
string
Public keychain
Yes
balanceStr
string
Initial balance, which must be a positive integer greater than or equal to 0. If the number contains decimal places, the value must be multiplied to eliminate the decimal places.
Yes
- Output
Parameter
Type
Description
balanceInfo
string
Transaction amount information
err
error
Error message
- Note
None
PrepareTxInfo
- API prototype
func PrepareTxInfo(cipherBalanceA string, transNumStr string, pubKeyA, pubKeyB string, privKeyA string,pwd string) (string, error)
- Function description
Transaction preparation
- Input
Parameter
Type
Description
Mandatory
cipherBalanceA
string
Current balance of user A (ciphertext), which is obtained from the blockchain.
Yes
transNumStr
string
Transfer amount (plaintext)
Yes
pubKeyA
string
Public keychain of user A
Yes
pubKeyB
string
Public keychain of user B
Yes
PrivKeyA
string
Private keychain of user A
Yes
pwd
string
Character string used for encryption
No
- Output
Parameter
Type
Description
Txinfo
string
Transaction preparation data
err
error
Error message
- Note
None
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot