Skip to content

Commit

Permalink
Added extension for security credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldwight committed Aug 5, 2023
1 parent 4dcea8d commit 8246cd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions MpesaSdk/Extensions/MpesaCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public static string EncryptPassword(string certificateFilePath, string password
return Convert.ToBase64String(data);
}

/// <summary>
/// Encrypts Mpesa API Security Credential password
/// </summary>
/// <param name="certificateDetails"></param>
/// <param name="password"></param>
/// <returns>
/// Encrypted Password
/// </returns>
public static string EncryptPasswordWithoutCertFile(string certificateDetails, string password)
{
var certificateDataResult = Encoding.UTF8.GetBytes(certificateDetails);

X509Certificate2 x509Certificate2 = new X509Certificate2(certificateDataResult);

using RSA rsa = x509Certificate2.GetRSAPublicKey();

var data = rsa.Encrypt(Encoding.UTF8.GetBytes(password), RSAEncryptionPadding.Pkcs1);

return Convert.ToBase64String(data);
}

/// <summary>
/// Reads and returns certificate data in bytes
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MpesaSdk/MpesaSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.0.20</Version>
<Version>1.0.21</Version>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'netstandard2.0'">
Expand Down

0 comments on commit 8246cd5

Please sign in to comment.