本文整理汇总了C++中TaoCrypt::FileSource方法的典型用法代码示例。如果您正苦于以下问题:C++ TaoCrypt::FileSource方法的具体用法?C++ TaoCrypt::FileSource怎么用?C++ TaoCrypt::FileSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaoCrypt
的用法示例。
在下文中一共展示了TaoCrypt::FileSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pkcs12_test
int pkcs12_test()
{
Source cert;
FileSource("../certs/server-cert.pem", cert);
if (cert.size() == 0) {
FileSource("../../certs/server-cert.pem", cert); // for testsuite
if (cert.size() == 0) {
FileSource("../../../certs/server-cert.pem", cert); // Debug dir
if (cert.size() == 0)
err_sys("where's your certs dir?", -109);
}
}
if (GetCert(cert) != 0)
return -110;
Source source;
FileSource("../certs/server.p12", source);
if (source.size() == 0) {
FileSource("../../certs/server.p12", source); // for testsuite
if (source.size() == 0) {
FileSource("../../../certs/server.p12", source); // Debug dir
if (source.size() == 0)
err_sys("where's your certs dir?", -111);
}
}
if (GetPKCS_Cert("password", source) != 0)
return -112;
return 0;
}
示例2: dsa_test
int dsa_test()
{
Source source;
FileSource("../certs/dsa512.der", source);
if (source.size() == 0) {
FileSource("../../certs/dsa512.der", source); // for testsuite
if (source.size() == 0) {
FileSource("../../../certs/dsa512.der", source); // win32 Debug dir
if (source.size() == 0)
err_sys("where's your certs dir?", -89);
}
}
const char msg[] = "this is the message";
byte signature[40];
DSA_PrivateKey priv(source);
DSA_Signer signer(priv);
SHA sha;
byte digest[SHA::DIGEST_SIZE];
sha.Update((byte*)msg, sizeof(msg));
sha.Final(digest);
signer.Sign(digest, signature, rng);
byte encoded[sizeof(signature) + 6];
byte decoded[40];
word32 encSz = EncodeDSA_Signature(signer.GetR(), signer.GetS(), encoded);
DecodeDSA_Signature(decoded, encoded, encSz);
DSA_PublicKey pub(priv);
DSA_Verifier verifier(pub);
if (!verifier.Verify(digest, decoded))
return -90;
return 0;
}
示例3: dh_test
int dh_test()
{
Source source;
FileSource("../certs/dh1024.dat", source);
if (source.size() == 0) {
FileSource("../../certs/dh1024.dat", source); // for testsuite
if (source.size() == 0) {
FileSource("../../../certs/dh1024.dat", source); // win32 Debug dir
if (source.size() == 0)
err_sys("where's your certs dir?", -79);
}
}
HexDecoder hDec(source);
DH dh(source);
byte pub[128];
byte priv[128];
byte agree[128];
byte pub2[128];
byte priv2[128];
byte agree2[128];
DH dh2(dh);
dh.GenerateKeyPair(rng, priv, pub);
dh2.GenerateKeyPair(rng, priv2, pub2);
dh.Agree(agree, priv, pub2);
dh2.Agree(agree2, priv2, pub);
if ( memcmp(agree, agree2, dh.GetByteLength()) )
return -80;
return 0;
}
示例4: rsa_test
int rsa_test()
{
Source source;
FileSource("../certs/client-key.der", source);
if (source.size() == 0) {
FileSource("../../certs/client-key.der", source); // for testsuite
if (source.size() == 0) {
FileSource("../../../certs/client-key.der", source); // Debug dir
if (source.size() == 0)
err_sys("where's your certs dir?", -79);
}
}
RSA_PrivateKey priv(source);
RSAES_Encryptor enc(priv);
byte message[] = "Everyone gets Friday off.";
const word32 len = (word32)strlen((char*)message);
byte cipher[64];
enc.Encrypt(message, len, cipher, rng);
RSAES_Decryptor dec(priv);
byte plain[64];
dec.Decrypt(cipher, sizeof(plain), plain, rng);
if (memcmp(plain, message, len))
return -70;
dec.SSL_Sign(message, len, cipher, rng);
if (!enc.SSL_Verify(message, len, cipher))
return -71;
// test decode
Source source2;
FileSource("../certs/client-cert.der", source2);
if (source2.size() == 0) {
FileSource("../../certs/client-cert.der", source2); // for testsuite
if (source2.size() == 0) {
FileSource("../../../certs/client-cert.der", source2); // Debug dir
if (source2.size() == 0)
err_sys("where's your certs dir?", -79);
}
}
CertDecoder cd(source2, true, 0, false, CertDecoder::CA);
if (cd.GetError().What())
err_sys("cert error", -80);
Source source3(cd.GetPublicKey().GetKey(), cd.GetPublicKey().size());
RSA_PublicKey pub(source3);
return 0;
}