Exemple #1
0
func generate() ([]byte, []byte, error) {
	privateKey, publicKey, err := bletchley.Generate()
	if err != nil {
		return []byte{}, []byte{}, err
	}

	privateKeyPEM := bletchley.PrivateKeyToPEM(privateKey)
	publicKeyPEM, err := bletchley.PublicKeyToPEM(publicKey)

	return publicKeyPEM, privateKeyPEM, err
}
Exemple #2
0
	})
})

var _ = Describe("Serialization of asymmetric keys", func() {
	var privateKey *rsa.PrivateKey

	BeforeEach(func() {
		nbits := 256
		var err error
		privateKey, err = rsa.GenerateKey(rand.Reader, nbits)
		Expect(err).To(BeNil())
	})

	Describe("private keys", func() {
		It("should serialize and deserialize losslessly", func() {
			pemBytes := bletchley.PrivateKeyToPEM(privateKey)

			Expect(bletchley.PEMToPrivateKey(pemBytes)).To(Equal(privateKey))
		})
	})

	Describe("public keys", func() {
		It("should serialize and deserialize losslessly", func() {
			publicKey := privateKey.Public().(*rsa.PublicKey)

			pemBytes, err := bletchley.PublicKeyToPEM(publicKey)
			Expect(err).NotTo(HaveOccurred())

			Expect(bletchley.PEMToPublicKey(pemBytes)).To(Equal(publicKey))
		})
	})