本文整理汇总了C++中SecureVector类的典型用法代码示例。如果您正苦于以下问题:C++ SecureVector类的具体用法?C++ SecureVector怎么用?C++ SecureVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SecureVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
SecureVector<Botan::byte> ne7ssh_keys::generateRSASignature (Botan::SecureVector<Botan::byte>& sessionID, Botan::SecureVector<Botan::byte>& signingData)
{
SecureVector<Botan::byte> sigRaw;
ne7ssh_string sigData, sig;
sigData.addVectorField (sessionID);
sigData.addVector (signingData);
if (!rsaPrivateKey)
{
ne7ssh::errors()->push (-1, "Private RSA key not initialized.");
return sig.value();
}
PK_Signer *RSASigner = get_pk_signer (*rsaPrivateKey, "EMSA3(SHA-1)");
#if BOTAN_PRE_18 || BOTAN_PRE_15
sigRaw = RSASigner->sign_message(sigData.value());
#else
sigRaw = RSASigner->sign_message(sigData.value(), *ne7ssh::rng);
#endif
if (!sigRaw.size())
{
ne7ssh::errors()->push (-1, "Failure while generating RSA signature.");
delete RSASigner;
return sig.value();
}
delete RSASigner;
sig.addString ("ssh-rsa");
sig.addVectorField (sigRaw);
return (sig.value());
}
示例2: pbkdf2_hmac_hash
OctetString pbkdf2_hmac_hash(const std::string& password, const SecureVector& salt, int desiredKeyLength, int iterations)
{
T hashObject;
Botan::HMAC hmac(&hashObject);
Botan::PKCS5_PBKDF2 pbkdf2(&hmac);
return pbkdf2.derive_key(desiredKeyLength, password, salt.data(), salt.size(), iterations);
}
示例3: BN_new
/*
* OSSL_BN Constructor
*/
OSSL_BN::OSSL_BN(const BigInt& in)
{
value = BN_new();
SecureVector<byte> encoding = BigInt::encode(in);
if(in != 0)
BN_bin2bn(encoding, encoding.size(), value);
}
示例4: to_ber
std::string to_ber() const
{
SecureVector<byte> bits = PKCS8::BER_encode(*rsa_key);
return std::string(reinterpret_cast<const char*>(&bits[0]),
bits.size());
}
示例5: bn2vector
void ne7ssh_string::addBigInt(const Botan::BigInt& bn)
{
SecureVector<Botan::byte> converted;
bn2vector(converted, bn);
uint32 nLen = htonl(converted.size());
_buffer += SecureVector<Botan::byte>((Botan::byte*)&nLen, sizeof(uint32));
_buffer += SecureVector<Botan::byte>(converted);
}
示例6:
void ne7ssh_crypt::decompressData (Botan::SecureVector<Botan::byte> &buffer)
{
SecureVector<Botan::byte> tmpVar;
if (!decompress) return;
tmpVar.swap (buffer);
decompress->process_msg (tmpVar);
tmpVar = decompress->read_all (compress->message_count() - 1);
buffer = Botan::SecureVector<Botan::byte>(tmpVar);
}
示例7:
/**
* Serialize a Certificate Verify message
*/
SecureVector<byte> Certificate_Verify::serialize() const
{
SecureVector<byte> buf;
const u16bit sig_len = signature.size();
buf.push_back(get_byte(0, sig_len));
buf.push_back(get_byte(1, sig_len));
buf += signature;
return buf;
}
示例8: ParseException
uint64_t Address::extract_stream_number(const std::string& address)
{
if(!check::address(address))
throw ParseException(__FILE__, __FUNCTION__, __LINE__, "Invalid address checksum");
int nb;
std::string addr = utils::remove_prefix(address, "BM-");
SecureVector bytes = decode::base58(addr);
decode::varint(bytes.data(), nb);
return decode::varint(&bytes[nb], nb);
}
示例9: while
/*
* Split up and process handshake messages
*/
void TLS_Server::read_handshake(byte rec_type,
const MemoryRegion<byte>& rec_buf)
{
if(rec_type == HANDSHAKE)
{
if(!state)
state = new Handshake_State;
state->queue.write(&rec_buf[0], rec_buf.size());
}
while(true)
{
Handshake_Type type = HANDSHAKE_NONE;
SecureVector<byte> contents;
if(rec_type == HANDSHAKE)
{
if(state->queue.size() >= 4)
{
byte head[4] = { 0 };
state->queue.peek(head, 4);
const size_t length = make_u32bit(0, head[1], head[2], head[3]);
if(state->queue.size() >= length + 4)
{
type = static_cast<Handshake_Type>(head[0]);
contents.resize(length);
state->queue.read(head, 4);
state->queue.read(&contents[0], contents.size());
}
}
}
else if(rec_type == CHANGE_CIPHER_SPEC)
{
if(state->queue.size() == 0 && rec_buf.size() == 1 && rec_buf[0] == 1)
type = HANDSHAKE_CCS;
else
throw Decoding_Error("Malformed ChangeCipherSpec message");
}
else
throw Decoding_Error("Unknown message type in handshake processing");
if(type == HANDSHAKE_NONE)
break;
process_handshake_msg(type, contents);
if(type == HANDSHAKE_CCS || !state)
break;
}
}
示例10: if
/*************************************************
* Decode a BigInt *
*************************************************/
BigInt BigInt::decode(const byte buf[], u32bit length, Base base)
{
BigInt r;
if(base == Binary)
r.binary_decode(buf, length);
#ifndef BOTAN_MINIMAL_BIGINT
else if(base == Hexadecimal)
{
SecureVector<byte> hex;
for(u32bit j = 0; j != length; ++j)
if(Hex_Decoder::is_valid(buf[j]))
hex.append(buf[j]);
u32bit offset = (hex.size() % 2);
SecureVector<byte> binary(hex.size() / 2 + offset);
if(offset)
{
byte temp[2] = { '0', hex[0] };
binary[0] = Hex_Decoder::decode(temp);
}
for(u32bit j = offset; j != binary.size(); ++j)
binary[j] = Hex_Decoder::decode(hex+2*j-offset);
r.binary_decode(binary, binary.size());
}
#endif
else if(base == Decimal || base == Octal)
{
const u32bit RADIX = ((base == Decimal) ? 10 : 8);
for(u32bit j = 0; j != length; ++j)
{
byte x = Charset::char2digit(buf[j]);
if(x >= RADIX)
{
if(RADIX == 10)
throw Invalid_Argument("BigInt: Invalid decimal string");
else
throw Invalid_Argument("BigInt: Invalid octal string");
}
r *= RADIX;
r += x;
}
}
else
throw Invalid_Argument("Unknown BigInt decoding method");
return r;
}
示例11: main
int main()
{
Botan::LibraryInitializer init;
AutoSeeded_RNG rng;
std::string passphrase = "secret";
std::ifstream infile("readme.txt");
std::ofstream outfile("readme.txt.enc");
PKCS5_PBKDF2 pbkdf2(new HMAC(new SHA_160));
pbkdf2.set_iterations(4096);
pbkdf2.new_random_salt(rng, 8);
SecureVector<byte> the_salt = pbkdf2.current_salt();
SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase).bits_of();
KDF* kdf = get_kdf("KDF2(SHA-1)");
SymmetricKey key = kdf->derive_key(20, master_key, "cipher key");
SymmetricKey mac_key = kdf->derive_key(20, master_key, "hmac key");
InitializationVector iv = kdf->derive_key(8, master_key, "cipher iv");
Pipe pipe(new Fork(
new Chain(
get_cipher("Blowfish/CBC/PKCS7", key, iv, ENCRYPTION),
new Base64_Encoder,
new DataSink_Stream(outfile)
),
new Chain(
new MAC_Filter("HMAC(SHA-1)", mac_key),
new Hex_Encoder)
)
);
outfile.write((const char*)the_salt.begin(), the_salt.size());
pipe.start_msg();
infile >> pipe;
pipe.end_msg();
SecureVector<byte> hmac = pipe.read_all(1);
outfile.write((const char*)hmac.begin(), hmac.size());
}
示例12: main
int main()
{
Botan::LibraryInitializer init;
try {
X509_Certificate mycert("mycert.pem");
X509_Certificate mycert2("mycert2.pem");
X509_Certificate yourcert("yourcert.pem");
X509_Certificate cacert("cacert.pem");
X509_Certificate int_ca("int_ca.pem");
AutoSeeded_RNG rng;
X509_Store store;
store.add_cert(mycert);
store.add_cert(mycert2);
store.add_cert(yourcert);
store.add_cert(int_ca);
store.add_cert(cacert, true);
const std::string msg = "prioncorp: we don't toy\n";
CMS_Encoder encoder(msg);
encoder.compress("Zlib");
encoder.digest();
encoder.encrypt(rng, mycert);
/*
PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", rng, "cut");
encoder.sign(store, *mykey);
*/
SecureVector<byte> raw = encoder.get_contents();
std::ofstream out("out.der");
out.write((const char*)raw.begin(), raw.size());
}
catch(std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
示例13: data
QByteArray SshAbstractCryptoFacility::generateHash(const SshKeyExchange &kex,
char c, quint32 length)
{
const QByteArray &k = kex.k();
const QByteArray &h = kex.h();
QByteArray data(k);
data.append(h).append(c).append(m_sessionId);
SecureVector<byte> key
= kex.hash()->process(convertByteArray(data), data.size());
while (key.size() < length) {
SecureVector<byte> tmpKey;
tmpKey += SecureVector<byte>(convertByteArray(k), k.size());
tmpKey += SecureVector<byte>(convertByteArray(h), h.size());
tmpKey += key;
key += kex.hash()->process(tmpKey);
}
return QByteArray(reinterpret_cast<const char *>(key.begin()), length);
}
示例14: password_hash_ok
bool password_hash_ok(const std::string& pass, const std::string& hash)
{
Pipe pipe(new Base64_Decoder);
pipe.start_msg();
pipe.write(hash);
pipe.end_msg();
SecureVector<byte> hash_bin = pipe.read_all();
PKCS5_PBKDF2 kdf(new HMAC(new SHA_160));
kdf.set_iterations(10000);
kdf.change_salt(hash_bin, 6);
SecureVector<byte> cmp = kdf.derive_key(12, pass).bits_of();
return same_mem(cmp.begin(), hash_bin.begin() + 6, 12);
}
示例15:
void ne7ssh_string::bn2vector(Botan::SecureVector<Botan::byte>& result, const Botan::BigInt& bi)
{
int high;
Botan::byte zero = '\0';
SecureVector<Botan::byte> strVector = BigInt::encode(bi);
high = (*(strVector.begin()) & 0x80) ? 1 : 0;
if (high)
{
result = SecureVector<Botan::byte>(&zero, 1);
}
else
{
result.clear();
}
result += strVector;
}