// TestRSAGenerateEnDe
func TestRSAGenerateEnDe(t *testing.T) {
	privBytes, pubBytes, err := utils.GenerateRSAKeyPair(1024)
	assert.Nil(t, err, "Fail to genereate RSA Key Pair")

	testData := []byte("This is the testdata for encrypt and decryp")
	encrypted, err := utils.RSAEncrypt(pubBytes, testData)
	assert.Nil(t, err, "Fail to encrypt data")
	decrypted, err := utils.RSADecrypt(privBytes, encrypted)
	assert.Nil(t, err, "Fail to decrypt data")
	assert.Equal(t, testData, decrypted, "Fail to get correct data after en/de")
}
Exemple #2
0
func (r LocalRepo) encrypt(method utils.EncryptMethod, content []byte) ([]byte, error) {
	switch method {
	case utils.EncryptRSA:
		pubBytes, err := ioutil.ReadFile(r.GetPublicKeyFile())
		if err != nil {
			return nil, err
		}
		return utils.RSAEncrypt(pubBytes, content)
	default:
		return content, nil
	}
}