License:
Author:
1 2 3 4 5 6 | auto cert = new Certificate(cast(char[])File("public.pem").read); auto pkey = new PrivateKey(cast(char[])File("private.pem").read);; auto ctx = new SSLCtx(); ctx.certificate = cert; ctx.pkey = pkey; ctx.checkKey(); |
1 2 3 4 5 6 7 8 9 10 | extern (C) { int myCallback(int code, X509_STORE_CTX *ctx) { auto myCtx = new CertificateStoreCtx(ctx); Certificate cert = myCtx.cert; Stdout(cert.subject).newline; return 0; // BAD CERT! (1 is good) } } |
1 2 3 4 5 6 7 8 | auto store = new CertificateStore(); auto caCert = new Certificate(cast(char[])File("cacert.pem").read); store.add(caCert); auto untrustedCert = new Certificate(cast(char[])File("cert.pem").read); if (untrustedCert.verify(store)) Stdout("The untrusted cert was signed by our caCert and is valid.").newline; else Stdout("The untrusted cert was expired, or not signed by the caCert").newline; |
1 2 3 | auto public = new PublicKey(cast(char[])File("public.pem").read); auto encrypted = public.encrypt(cast(ubyte[])"Hello, how are you today?"); auto pemData = public.pemFormat; |
Parameters:
publicPemData | pem encoded data containing the public key |
Parameters:
data | the data to verify |
signature | the digital signature |
Notes:
Parameters:
data | the data to encrypt |
Parameters:
data | the data to encrypt |
1 2 3 4 5 | auto newPkey = new PrivateKey(2048); // create new keypair Stdout(newPkey.pemFormat("password")); // dumps in pemFormat with encryption Stdout(newPkey.pemFormat()); // dumps in pemFormat without encryption Stdout(newPkey.publicKey.pemFormat); // dump out just the public key portion auto data = newPkey.decrypt(someData); // decrypt data encrypted with public Key |
Parameters:
privatePemData | the PEM encoded data of the private key |
certPass | an optional password to decrypt the key. |
Parameters:
bits | Number of bits to use, 2048 is a good number for this. |
Parameters:
pass | If this is provided, the private key will be encrypted using AES 256bit encryption, with this as the key. |
Parameters:
data | the data to sign |
sigbuf | the buffer to store the signature in Returns a slice of the signature or null |
Notes:
Parameters:
data | the data to encrypt |
Parmas:
1 2 3 4 5 6 7 8 9 10 | auto newPkey = new PrivateKey(2048); // create new keypair auto cert = new Certificate(); cert.privateKey = newPkey; cert.serialNumber = 1; cert.dateBeforeOffset = TimeSpan.zero; cert.dateAfterOffset = TimeSpan.days(365); // cert is valid for one year cert.setSubject("US", "State", "City", "Organization", "CN", "Organizational Unit", "Email"); cert.sign(cert, newPkey); // self signed cert Stdout(newPkey.pemFormat).newline; Stdout(cert.pemFormat).newline; |
Parameters:
t | A TimeSpan representing the earliest time the Certificate will be valid |
Example:
Parameters:
t | A TimeSpan representing the amount of time from now that the Certificate will be valid. This must be larger than dateBefore |
Example:
Parameters:
country | the two letter country code of the subject |
stateProvince | the state or province of the subject |
city | the city the subject belong to |
organization | the organization the subject belongs to |
cn | the cn of the subject. For websites, this should be the website url or a wildcard version of it (ie: *.dsource.org) |
organizationUnit | the optional orgnizationalUnit of the subject |
the optional email address of the subject |