Skip to content

Commit

Permalink
tweak EncryptSharedString
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Oct 30, 2020
1 parent 1da9b71 commit b07acf6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ func EncryptShared(user1PrivateKey *bsvec.PrivateKey, user2PubKey *bsvec.PublicK
return sharedPrivKey, sharedPubKey, encryptedData, err
}

// EncryptSharedString will encrypt data and provide shared keys for decryption
// EncryptSharedString will encrypt a string to a hex encoded encrypted payload, and provide shared keys for decryption
func EncryptSharedString(user1PrivateKey *bsvec.PrivateKey, user2PubKey *bsvec.PublicKey, data string) (
*bsvec.PrivateKey, *bsvec.PublicKey, string, error) {

// Generate shared keys that can be decrypted by either user
sharedPrivKey, sharedPubKey := GenerateSharedKeyPair(user1PrivateKey, user2PubKey)
sharedPrivKey, sharedPubKey, encryptedData, err := EncryptShared(user1PrivateKey, user2PubKey, []byte(data))

// Encrypt data with shared key
encryptedData, err := bsvec.Encrypt(sharedPubKey, []byte(data))
return sharedPrivKey, sharedPubKey, hex.EncodeToString(encryptedData), err
}

0 comments on commit b07acf6

Please sign in to comment.