use aes256 for password encryption (#75)

This commit is contained in:
Ilya Chesnokov 2020-08-31 13:42:06 +03:00 committed by GitHub
parent 39c2fa863e
commit 1f4d966115
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View file

@ -41,6 +41,7 @@ DecryptBinaryMessageArmored(privateKey string, passphrase []byte, ciphertext str
- Improved key and message armoring testing - Improved key and message armoring testing
- `EncryptSessionKey` now creates encrypted key packets for each valid encryption key in the provided keyring. - `EncryptSessionKey` now creates encrypted key packets for each valid encryption key in the provided keyring.
Returns a byte slice with all the concatenated key packets. Returns a byte slice with all the concatenated key packets.
- Use aes256 chiper for message encryption with password.
### Fixed ### Fixed
- Public key armoring headers - Public key armoring headers

View file

@ -3,6 +3,7 @@ package crypto
import ( import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"io"
"testing" "testing"
"time" "time"
@ -18,6 +19,24 @@ func TestTextMessageEncryptionWithPassword(t *testing.T) {
if err != nil { if err != nil {
t.Fatal("Expected no error when encrypting, got:", err) t.Fatal("Expected no error when encrypting, got:", err)
} }
packets := packet.NewReader(bytes.NewReader(encrypted.GetBinary()))
var foundSk bool
for {
var p packet.Packet
var errEOF error
if p, errEOF = packets.Next(); errEOF == io.EOF {
break
}
sessionKey, ok := p.(*packet.SymmetricKeyEncrypted)
if ok {
assert.Equal(t, sessionKey.CipherFunc, packet.CipherAES256)
foundSk = true
break
}
}
if !foundSk {
t.Fatal("Expect to found encrypted session key")
}
// Decrypt data with wrong password // Decrypt data with wrong password
_, err = DecryptMessageWithPassword(encrypted, []byte("Wrong password")) _, err = DecryptMessageWithPassword(encrypted, []byte("Wrong password"))
assert.NotNil(t, err) assert.NotNil(t, err)

View file

@ -114,7 +114,8 @@ func passwordEncrypt(message []byte, password []byte, isBinary bool) ([]byte, er
var outBuf bytes.Buffer var outBuf bytes.Buffer
config := &packet.Config{ config := &packet.Config{
Time: getTimeGenerator(), DefaultCipher: packet.CipherAES256,
Time: getTimeGenerator(),
} }
hints := &openpgp.FileHints{IsBinary: isBinary} hints := &openpgp.FileHints{IsBinary: isBinary}