CertificateHolderCreate Method (Byte, SecureString) |
Creates CertificateHolder object using byte array of PKCS12 store and its password.
Namespace:
Aspose.Words
Assembly:
Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntaxpublic static CertificateHolder Create(
byte[] certBytes,
SecureString password
)
Public Shared Function Create (
certBytes As Byte(),
password As SecureString
) As CertificateHolder
public:
static CertificateHolder^ Create(
array<unsigned char>^ certBytes,
SecureString^ password
)
static member Create :
certBytes : byte[] *
password : SecureString -> CertificateHolder
Parameters
- certBytes
- Type: SystemByte
A byte array that contains data from an X.509 certificate. - password
- Type: System.SecuritySecureString
The password required to access the X.509 certificate data.
Return Value
Type:
CertificateHolderAn instance of CertificateHolder
ExceptionsException | Condition |
---|
InvalidParameterException | Thrown if certBytes is null |
InvalidParameterException | Thrown if password is null |
SecurityException | Thrown if PKCS12 store contains no aliases |
IOException | Thrown if there is wrong password or corrupted file. |
ExamplesShows how to create CertificateHolder objects.
byte[] certBytes = File.ReadAllBytes(MyDir + "morzal.pfx");
CertificateHolder.Create(certBytes, "aw");
SecureString password = new NetworkCredential("", "aw").SecurePassword;
CertificateHolder.Create(certBytes, password);
using (FileStream certStream = new FileStream(MyDir + "morzal.pfx", FileMode.Open))
{
Pkcs12Store pkcs12Store = new Pkcs12Store(certStream, "aw".ToCharArray());
IEnumerator enumerator = pkcs12Store.Aliases.GetEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Current != null)
{
string currentAlias = enumerator.Current.ToString();
if (pkcs12Store.IsKeyEntry(currentAlias) && pkcs12Store.GetKey(currentAlias).Key.IsPrivate)
{
Console.WriteLine($"Valid alias found: {enumerator.Current}");
}
}
}
}
CertificateHolder.Create(MyDir + "morzal.pfx", "aw", "c20be521-11ea-4976-81ed-865fbbfc9f24");
CertificateHolder.Create(MyDir + "morzal.pfx", "aw", null);
See Also