Reduce return values for mobile compatibility
This commit is contained in:
76
asymcrypt.go
76
asymcrypt.go
@ -100,38 +100,42 @@ func AsymDecryptArmored(PrivateKey string, data []byte) ([]byte, error) {
|
||||
return []byte(decrypted), err
|
||||
}
|
||||
|
||||
func AsymEncryptAndSign_helpers(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) {
|
||||
pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
/*
|
||||
func AsymEncryptAndSign_helpers(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) (*EncryptedMessage, error) {
|
||||
var enc EncryptedMessage
|
||||
pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
}
|
||||
priv, err := base64.StdEncoding.DecodeString(PrivateSignatureKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
}
|
||||
encrypted, signature, err := helper.EncryptSignBinaryDetached(string(pub), string(priv), nil, data)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign failed")
|
||||
}
|
||||
enc.data = []byte(encrypted)
|
||||
enc.signature = []byte(signature)
|
||||
return &enc, err
|
||||
}
|
||||
priv, err := base64.StdEncoding.DecodeString(PrivateSignatureKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
}
|
||||
encrypted, signature, err := helper.EncryptSignBinaryDetached(string(pub), string(priv), nil, data)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign failed")
|
||||
}
|
||||
return []byte(encrypted), []byte(signature), err
|
||||
}
|
||||
|
||||
func AsymDecryptAndCheck_helpers(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) {
|
||||
priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
func AsymDecryptAndCheck_helpers(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) {
|
||||
priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
}
|
||||
pub, err := base64.StdEncoding.DecodeString(MyContactPublicKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
}
|
||||
DecryptedMessage, err = helper.DecryptVerifyBinaryDetached(string(pub), string(priv), nil, data, string(Signature))
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign failed")
|
||||
}
|
||||
return DecryptedMessage, err
|
||||
}
|
||||
pub, err := base64.StdEncoding.DecodeString(MyContactPublicKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
}
|
||||
DecryptedMessage, err = helper.DecryptVerifyBinaryDetached(string(pub), string(priv), nil, data, string(Signature))
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign failed")
|
||||
}
|
||||
return DecryptedMessage, err
|
||||
}
|
||||
|
||||
*/
|
||||
func encryptMessage(key string, message *crypto.PlainMessage) (*crypto.PGPMessage, error) {
|
||||
publicKeyRing, err := createPublicKeyRing(key)
|
||||
if err != nil {
|
||||
@ -193,35 +197,43 @@ func createPublicKeyRing(publicKey string) (*crypto.KeyRing, error) {
|
||||
return publicKeyRing, nil
|
||||
}
|
||||
|
||||
func AsymEncryptAndSign(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) ([]byte, []byte, error) {
|
||||
func AsymEncryptAndSign(PublicEncryptionKey string, PrivateSignatureKey string, data []byte) (*EncryptedMessage, error) {
|
||||
var enc EncryptedMessage
|
||||
pub, err := base64.StdEncoding.DecodeString(PublicEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
return nil, err
|
||||
}
|
||||
priv, err := base64.StdEncoding.DecodeString(PrivateSignatureKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption and sign b64 failed")
|
||||
return nil, err
|
||||
}
|
||||
ciphertext, signature, err := encryptAndSignMessage(string(pub), string(priv), crypto.NewPlainMessage(data))
|
||||
if err != nil {
|
||||
log.Error().Msg("Message encryption failed")
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return ciphertext.GetBinary(), signature, err
|
||||
enc.Data = ciphertext.GetBinary()
|
||||
enc.Signature = []byte(signature)
|
||||
return &enc, err
|
||||
}
|
||||
|
||||
func AsymDecryptAndCheck(MyPrivateEncryptionKey string, MyContactPublicKey string, data []byte, Signature []byte) (DecryptedMessage []byte, err error) {
|
||||
priv, err := base64.StdEncoding.DecodeString(MyPrivateEncryptionKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
return nil, err
|
||||
}
|
||||
pub, err := base64.StdEncoding.DecodeString(MyContactPublicKey)
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign b64 failed")
|
||||
return nil, err
|
||||
}
|
||||
DecryptedMessage, err = decryptAndCheckMessage(string(pub), string(priv), crypto.NewPGPMessage(data), crypto.NewPGPSignature(Signature))
|
||||
if err != nil {
|
||||
log.Error().Msg("Message decryption and sign failed")
|
||||
return nil, err
|
||||
}
|
||||
return DecryptedMessage, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user