return decrypt error
This commit is contained in:
parent
79a677eb2c
commit
8f4bbfc780
3 changed files with 11 additions and 11 deletions
|
|
@ -78,8 +78,8 @@ func newSymmetricKey(ek *packet.EncryptedKey) *SymmetricKey {
|
|||
}
|
||||
}
|
||||
|
||||
// DecryptAttKey and return a symmetric key
|
||||
// Use: bridge
|
||||
// Decrypt and return a symmetric key
|
||||
func DecryptAttKey(kr *KeyRing, keyPacket string) (key *SymmetricKey, err error) {
|
||||
r := base64.NewDecoder(base64.StdEncoding, strings.NewReader(keyPacket))
|
||||
packets := packet.NewReader(r)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import (
|
|||
"golang.org/x/crypto/openpgp/packet"
|
||||
)
|
||||
|
||||
// Use: ios/android only
|
||||
//RandomToken ...
|
||||
// Use: ios/android only
|
||||
func (pm *PmCrypto) RandomToken() ([]byte, error) {
|
||||
config := &packet.Config{DefaultCipher: packet.CipherAES256}
|
||||
keySize := config.DefaultCipher.KeySize()
|
||||
|
|
@ -23,8 +23,8 @@ func (pm *PmCrypto) RandomToken() ([]byte, error) {
|
|||
return symKey, nil
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
// RandomTokenWith ...
|
||||
// Use: ios/android only
|
||||
func (pm *PmCrypto) RandomTokenWith(size int) ([]byte, error) {
|
||||
config := &packet.Config{DefaultCipher: packet.CipherAES256}
|
||||
symKey := make([]byte, size)
|
||||
|
|
@ -34,8 +34,8 @@ func (pm *PmCrypto) RandomTokenWith(size int) ([]byte, error) {
|
|||
return symKey, nil
|
||||
}
|
||||
|
||||
// GetSessionFromKeyPacket get session key no encoding in and out
|
||||
// Use: ios/android only
|
||||
//GetSessionFromKeyPacketBinkeys get session key no encoding in and out
|
||||
func (pm *PmCrypto) GetSessionFromKeyPacket(keyPackage []byte, privateKey *KeyRing, passphrase string) (*SymmetricKey, error) {
|
||||
|
||||
keyReader := bytes.NewReader(keyPackage)
|
||||
|
|
@ -68,14 +68,14 @@ func (pm *PmCrypto) GetSessionFromKeyPacket(keyPackage []byte, privateKey *KeyRi
|
|||
}
|
||||
|
||||
if decryptErr != nil {
|
||||
return nil, err
|
||||
return nil, decryptErr
|
||||
}
|
||||
|
||||
return getSessionSplit(ek)
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
//KeyPacketWithPublicKey ...
|
||||
// Use: ios/android only
|
||||
func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *SymmetricKey, publicKey string) ([]byte, error) {
|
||||
pubkeyRaw, err := armor.Unarmor(publicKey)
|
||||
if err != nil {
|
||||
|
|
@ -84,8 +84,8 @@ func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *SymmetricKey, publicKey
|
|||
return pm.KeyPacketWithPublicKeyBin(sessionSplit, pubkeyRaw)
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
// KeyPacketWithPublicKeyBin ...
|
||||
// Use: ios/android only
|
||||
func (pm *PmCrypto) KeyPacketWithPublicKeyBin(sessionSplit *SymmetricKey, publicKey []byte) ([]byte, error) {
|
||||
publicKeyReader := bytes.NewReader(publicKey)
|
||||
pubKeyEntries, err := openpgp.ReadKeyRing(publicKeyReader)
|
||||
|
|
@ -169,8 +169,8 @@ func (pm *PmCrypto) GetSessionFromSymmetricPacket(keyPackage []byte, password st
|
|||
return nil, errors.New("password incorrect")
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
// SymmetricKeyPacketWithPassword ...
|
||||
// Use: ios/android only
|
||||
func (pm *PmCrypto) SymmetricKeyPacketWithPassword(sessionSplit *SymmetricKey, password string) ([]byte, error) {
|
||||
outbuf := &bytes.Buffer{}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import (
|
|||
"golang.org/x/crypto/scrypt"
|
||||
)
|
||||
|
||||
// Use: ios/android only
|
||||
// EncryptWithoutIntegrity encrypts data with AES-CTR. Note: this encryption mode is not secure when stored/sent on an untrusted medium.
|
||||
// Use: ios/android only
|
||||
func EncryptWithoutIntegrity(key, input, iv []byte) (output []byte, err error) {
|
||||
var block cipher.Block
|
||||
if block, err = aes.NewCipher(key); err != nil {
|
||||
|
|
@ -20,15 +20,15 @@ func EncryptWithoutIntegrity(key, input, iv []byte) (output []byte, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
// DecryptWithoutIntegrity decrypts data encrypted with AES-CTR.
|
||||
// Use: ios/android only
|
||||
func DecryptWithoutIntegrity(key, input, iv []byte) ([]byte, error) {
|
||||
// AES-CTR decryption is identical to encryption.
|
||||
return EncryptWithoutIntegrity(key, input, iv)
|
||||
}
|
||||
|
||||
// Use: ios/android only
|
||||
// DeriveKey derives a key from a password using scrypt. N should be set to the highest power of 2 you can derive within 100 milliseconds.
|
||||
// Use: ios/android only
|
||||
func DeriveKey(password string, salt []byte, N int) ([]byte, error) {
|
||||
return scrypt.Key([]byte(password), salt, N, 8, 1, 32)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue