2fas-server/internal/common/crypto/rsa_test.go

24 lines
566 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package crypto
import (
"github.com/stretchr/testify/assert"
"testing"
)
func Test_ConvertKeyPairToStringAndBackward(t *testing.T) {
keyPair := GenerateKeyPair(2048)
privateKeyAsPemStr := ExportRsaPrivateKeyAsPemStr(keyPair.PrivateKey)
publicKeyAsPemStr := ExportRsaPublicKeyAsPemStr(keyPair.PublicKey)
assert.NotEmpty(t, publicKeyAsPemStr)
_, err := ParseRsaPrivateKeyFromPemStr(privateKeyAsPemStr)
assert.NoError(t, err, "Cannot convert PEM string to private key")
_, err = ParseRsaPublicKeyFromPemStr(publicKeyAsPemStr)
assert.NoError(t, err)
}