本文整理汇总了C++中base64Decode函数的典型用法代码示例。如果您正苦于以下问题:C++ base64Decode函数的具体用法?C++ base64Decode怎么用?C++ base64Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了base64Decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseSPropParameterSets
SPropRecord* parseSPropParameterSets(char const* sPropParameterSetsStr,
// result parameter:
unsigned& numSPropRecords) {
// Make a copy of the input string, so we can replace the commas with '\0's:
char* inStr = strDup(sPropParameterSetsStr);
if (inStr == NULL) {
numSPropRecords = 0;
return NULL;
}
// Count the number of commas (and thus the number of parameter sets):
numSPropRecords = 1;
char* s;
for (s = inStr; *s != '\0'; ++s) {
if (*s == ',') {
++numSPropRecords;
*s = '\0';
}
}
// Allocate and fill in the result array:
SPropRecord* resultArray = new SPropRecord[numSPropRecords];
s = inStr;
for (unsigned i = 0; i < numSPropRecords; ++i) {
resultArray[i].sPropBytes = base64Decode(s, resultArray[i].sPropLength);
s += strlen(s) + 1;
}
delete[] inStr;
return resultArray;
}
示例2: problem20
void problem20(void){
string *ciphers;
string keystream;
int numCiphers;
int i;
char *line;
FILE *fp;
numCiphers=0;
fp = fopen(FILE20, "r");
for(i=0; !feof(fp); ) if(fgetc(fp)=='\n') i++;
fclose(fp);
numCiphers=++i;
ciphers=malloc(sizeof(string)*(numCiphers));
fp=fopen(FILE20, "r");
line=malloc(sizeof(char)*(161));
for(i=0; i<numCiphers; i++){
fscanf(fp, "%s", line);
ciphers[i]=base64Decode(newString(line,0));
}
fclose(fp);
keystream=breakFixedNonceCTRAsRepeatedXOR(ciphers, numCiphers);
keystream=modifyKey(keystream, ciphers, numCiphers);
}
示例3: String
void Page::userStyleSheetLocationChanged()
{
// FIXME: Eventually we will move to a model of just being handed the sheet
// text instead of loading the URL ourselves.
KURL url = m_settings->userStyleSheetLocation();
if (url.isLocalFile())
m_userStyleSheetPath = url.fileSystemPath();
else
m_userStyleSheetPath = String();
m_didLoadUserStyleSheet = false;
m_userStyleSheet = String();
m_userStyleSheetModificationTime = 0;
// Data URLs with base64-encoded UTF-8 style sheets are common. We can process them
// synchronously and avoid using a loader.
if (url.protocolIs("data") && url.string().startsWith("data:text/css;charset=utf-8;base64,")) {
m_didLoadUserStyleSheet = true;
const unsigned prefixLength = 35;
Vector<char> encodedData(url.string().length() - prefixLength);
for (unsigned i = prefixLength; i < url.string().length(); ++i)
encodedData[i - prefixLength] = static_cast<char>(url.string()[i]);
Vector<char> styleSheetAsUTF8;
if (base64Decode(encodedData, styleSheetAsUTF8))
m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size());
}
for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (frame->document())
frame->document()->clearPageUserSheet();
}
}
示例4: ABC_CHECK
Status
JsonBox::decrypt(DataChunk &result, DataSlice key)
{
DataChunk nonce;
ABC_CHECK(nonceOk());
ABC_CHECK(base16Decode(nonce, this->nonce()));
DataChunk cyphertext;
ABC_CHECK(cyphertextOk());
ABC_CHECK(base64Decode(cyphertext, this->cyphertext()));
switch (type())
{
case AES256_CBC_AIRBITZ:
{
ABC_CHECK_OLD(ABC_CryptoDecryptAES256Package(result,
cyphertext, key, nonce,
&error));
return Status();
}
default:
return ABC_ERROR(ABC_CC_DecryptError, "Unknown encryption type");
}
}
示例5: LOGD
void MyResourceLoader::loadData(const String& data)
{
LOGD("Loading data (%s) ...", data.latin1().data());
ResourceHandleClient* client = m_handle->client();
int index = data.find(',');
if (index == -1) {
client->cannotShowURL(m_handle);
return;
}
String mediaType = data.substring(0, index);
String base64 = data.substring(index + 1);
bool decode = mediaType.endsWith(";base64", false);
if (decode)
mediaType = mediaType.left(mediaType.length() - 7); // 7 for base64;
if (mediaType.isEmpty())
mediaType = "text/plain;charset=US-ASCII";
String mimeType = extractMIMETypeFromMediaType(mediaType);
String charset = extractCharsetFromMediaType(mediaType);
ResourceResponse response;
response.setMimeType(mimeType);
if (decode) {
base64 = decodeURLEscapeSequences(base64);
response.setTextEncodingName(charset);
client->didReceiveResponse(m_handle, response);
// FIXME: This is annoying. WebCore's Base64 decoder chokes on spaces.
// That is correct with strict decoding but html authors (particularly
// the acid3 authors) put spaces in the data which should be ignored.
// Remove them here before sending to the decoder.
Vector<char> in;
CString str = base64.latin1();
const char* chars = str.data();
unsigned i = 0;
while (i < str.length()) {
char c = chars[i];
// Don't send spaces or control characters.
if (c != ' ' && c != '\n' && c != '\t' && c != '\b'
&& c != '\f' && c != '\r')
in.append(chars[i]);
i++;
}
Vector<char> out;
if (base64Decode(in, out) && out.size() > 0)
client->didReceiveData(m_handle, out.data(), out.size(), 0);
} else {
base64 = decodeURLEscapeSequences(base64, TextEncoding(charset));
response.setTextEncodingName("UTF-16");
client->didReceiveResponse(m_handle, response);
if (base64.length() > 0)
client->didReceiveData(m_handle, (const char*)base64.characters(),
base64.length() * sizeof(UChar), 0);
}
client->didFinishLoading(m_handle, 0);
}
示例6: throwError
JSValue JSDOMWindow::atob(ExecState* exec, const ArgList& args)
{
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
JSValue v = args.at(0);
if (v.isNull())
return jsEmptyString(exec);
UString s = v.toString(exec);
if (!s.is8Bit()) {
setDOMException(exec, INVALID_CHARACTER_ERR);
return jsUndefined();
}
Vector<char> in(s.size());
for (int i = 0; i < s.size(); ++i)
in[i] = static_cast<char>(s.data()[i]);
Vector<char> out;
if (!base64Decode(in, out))
return throwError(exec, GeneralError, "Cannot decode base64");
return jsString(exec, String(out.data(), out.size()));
}
示例7: String
void Page::userStyleSheetLocationChanged()
{
// FIXME: Eventually we will move to a model of just being handed the sheet
// text instead of loading the URL ourselves.
KURL url = m_settings->userStyleSheetLocation();
m_didLoadUserStyleSheet = false;
m_userStyleSheet = String();
m_userStyleSheetModificationTime = 0;
// Data URLs with base64-encoded UTF-8 style sheets are common. We can process them
// synchronously and avoid using a loader.
if (url.protocolIsData() && url.string().startsWith("data:text/css;charset=utf-8;base64,")) {
m_didLoadUserStyleSheet = true;
Vector<char> styleSheetAsUTF8;
if (base64Decode(decodeURLEscapeSequences(url.string().substring(35)), styleSheetAsUTF8, Base64IgnoreWhitespace))
m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size());
}
for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (frame->document())
frame->document()->styleSheetCollection()->updatePageUserSheet();
}
}
示例8: problem18
void problem18(void){
/* Implement CTR, the stream-cipher mode.*/
string cipher=base64Decode(newString("L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==",0));
string key=newString("YELLOW SUBMARINE",0);
string nonce=newString(NULL,8);
string plaintext=AES128CTR(cipher, key, nonce);
printf("The CTR-mode encrypted cipher \n"); printsint(cipher);printf("\ndecrypts to \n");prints(plaintext);printf("\n");
}
示例9: TEST_F
TEST_F(ConversionsTests, test_base64) {
std::string unencoded = "HELLO";
auto encoded = base64Encode(unencoded);
EXPECT_NE(encoded.size(), 0U);
auto unencoded2 = base64Decode(encoded);
EXPECT_EQ(unencoded, unencoded2);
}
示例10: SetUp
virtual void SetUp() {
std::string raw;
CFDataRef data;
raw = base64Decode(getCACertificateContent());
data = CFDataCreate(NULL, (const UInt8*)raw.c_str(), (CFIndex)raw.size());
cert = SecCertificateCreateWithData(NULL, data);
CFRelease(data);
}
示例11: parseApplicationAliasData
Status parseApplicationAliasData(const std::string& data, std::string& result) {
std::string decoded_data = base64Decode(data);
if (decoded_data.empty()) {
return Status(1, "Failed to base64 decode data");
}
CFDataRef resourceData = CFDataCreate(
nullptr,
static_cast<const UInt8*>(static_cast<const void*>(decoded_data.c_str())),
decoded_data.length());
if (resourceData == nullptr) {
return Status(1, "Failed to allocate resource data");
}
auto alias = (CFDataRef)CFPropertyListCreateWithData(kCFAllocatorDefault,
resourceData,
kCFPropertyListImmutable,
nullptr,
nullptr);
CFRelease(resourceData);
if (alias == nullptr) {
return Status(1, "Failed to allocate alias data");
}
auto bookmark =
CFURLCreateBookmarkDataFromAliasRecord(kCFAllocatorDefault, alias);
CFRelease(alias);
if (bookmark == nullptr) {
return Status(1, "Alias data is not a bookmark");
}
auto url = CFURLCreateByResolvingBookmarkData(
kCFAllocatorDefault, bookmark, 0, nullptr, nullptr, nullptr, nullptr);
CFRelease(bookmark);
if (url == nullptr) {
return Status(1, "Alias data is not a URL bookmark");
}
auto replaced = CFURLCreateStringByReplacingPercentEscapes(
kCFAllocatorDefault, CFURLGetString(url), CFSTR(""));
CFRelease(url);
if (replaced == nullptr) {
return Status(1, "Failed to replace percent escapes.");
}
// Get the URL-formatted path.
result = stringFromCFString(replaced);
CFRelease(replaced);
if (result.empty()) {
return Status(1, "Return result is zero size");
}
if (result.length() > 6 && result.substr(0, 7) == "file://") {
result = result.substr(7);
}
return Status(0, "OK");
}
示例12: ASSERT
// hash-source = "'" hash-algorithm "-" hash-value "'"
// hash-algorithm = "sha1" / "sha256" / "sha384" / "sha512"
// hash-value = 1*( ALPHA / DIGIT / "+" / "/" / "=" )
//
bool CSPSourceList::parseHash(const UChar* begin, const UChar* end, DigestValue& hash, ContentSecurityPolicyHashAlgorithm& hashAlgorithm)
{
// Any additions or subtractions from this struct should also modify the
// respective entries in the kAlgorithmMap array in checkDigest().
static const struct {
const char* prefix;
ContentSecurityPolicyHashAlgorithm type;
} kSupportedPrefixes[] = {
// FIXME: Drop support for SHA-1. It's not in the spec.
{ "'sha1-", ContentSecurityPolicyHashAlgorithmSha1 },
{ "'sha256-", ContentSecurityPolicyHashAlgorithmSha256 },
{ "'sha384-", ContentSecurityPolicyHashAlgorithmSha384 },
{ "'sha512-", ContentSecurityPolicyHashAlgorithmSha512 },
{ "'sha-256-", ContentSecurityPolicyHashAlgorithmSha256 },
{ "'sha-384-", ContentSecurityPolicyHashAlgorithmSha384 },
{ "'sha-512-", ContentSecurityPolicyHashAlgorithmSha512 }
};
String prefix;
hashAlgorithm = ContentSecurityPolicyHashAlgorithmNone;
size_t hashLength = end - begin;
for (const auto& algorithm : kSupportedPrefixes) {
if (hashLength > strlen(algorithm.prefix) && equalIgnoringCase(algorithm.prefix, begin, strlen(algorithm.prefix))) {
prefix = algorithm.prefix;
hashAlgorithm = algorithm.type;
break;
}
}
if (hashAlgorithm == ContentSecurityPolicyHashAlgorithmNone)
return true;
const UChar* position = begin + prefix.length();
const UChar* hashBegin = position;
ASSERT(position < end);
skipWhile<UChar, isBase64EncodedCharacter>(position, end);
ASSERT(hashBegin <= position);
// Base64 encodings may end with exactly one or two '=' characters
if (position < end)
skipExactly<UChar>(position, position + 1, '=');
if (position < end)
skipExactly<UChar>(position, position + 1, '=');
if (position + 1 != end || *position != '\'' || position == hashBegin)
return false;
Vector<char> hashVector;
// We accept base64url-encoded data here by normalizing it to base64.
base64Decode(normalizeToBase64(String(hashBegin, position - hashBegin)), hashVector);
if (hashVector.size() > kMaxDigestSize)
return false;
hash.append(reinterpret_cast<uint8_t*>(hashVector.data()), hashVector.size());
return true;
}
示例13: ASSERT
// hash-source = "'" hash-algorithm "-" hash-value "'"
// hash-algorithm = "sha1" / "sha256" / "sha384" / "sha512"
// hash-value = 1*( ALPHA / DIGIT / "+" / "/" / "=" )
//
bool CSPSourceList::parseHash(const UChar* begin, const UChar* end, DigestValue& hash, ContentSecurityPolicyHashAlgorithm& hashAlgorithm)
{
// Any additions or subtractions from this struct should also modify the
// respective entries in the kAlgorithmMap array in checkDigest().
static const struct {
const char* prefix;
ContentSecurityPolicyHashAlgorithm algorithm;
} kSupportedPrefixes[] = {
{ "'sha1-", ContentSecurityPolicyHashAlgorithmSha1 },
{ "'sha256-", ContentSecurityPolicyHashAlgorithmSha256 },
{ "'sha384-", ContentSecurityPolicyHashAlgorithmSha384 },
{ "'sha512-", ContentSecurityPolicyHashAlgorithmSha512 }
};
String prefix;
hashAlgorithm = ContentSecurityPolicyHashAlgorithmNone;
// Instead of this sizeof() calculation to get the length of this array,
// it would be preferable to use WTF_ARRAY_LENGTH for simplicity and to
// guarantee a compile time calculation. Unfortunately, on some
// compliers, the call to WTF_ARRAY_LENGTH fails on arrays of anonymous
// stucts, so, for now, it is necessary to resort to this sizeof
// calculation.
for (size_t i = 0; i < (sizeof(kSupportedPrefixes) / sizeof(kSupportedPrefixes[0])); i++) {
if (equalIgnoringCase(kSupportedPrefixes[i].prefix, begin, strlen(kSupportedPrefixes[i].prefix))) {
prefix = kSupportedPrefixes[i].prefix;
hashAlgorithm = kSupportedPrefixes[i].algorithm;
break;
}
}
if (hashAlgorithm == ContentSecurityPolicyHashAlgorithmNone)
return true;
const UChar* position = begin + prefix.length();
const UChar* hashBegin = position;
skipWhile<UChar, isBase64EncodedCharacter>(position, end);
ASSERT(hashBegin <= position);
// Base64 encodings may end with exactly one or two '=' characters
skipExactly<UChar>(position, position + 1, '=');
skipExactly<UChar>(position, position + 1, '=');
if ((position + 1) != end || *position != '\'' || !(position - hashBegin))
return false;
Vector<char> hashVector;
base64Decode(hashBegin, position - hashBegin, hashVector);
if (hashVector.size() > kMaxDigestSize)
return false;
hash.append(reinterpret_cast<uint8_t*>(hashVector.data()), hashVector.size());
return true;
}
示例14: handleDataURL
void handleDataURL(ResourceHandle* handle)
{
ASSERT(handle->firstRequest().url().protocolIs("data"));
String url = handle->firstRequest().url().string();
int index = url.find(',');
if (index == -1) {
handle->client()->cannotShowURL(handle);
return;
}
String mediaType = url.substring(5, index - 5);
String data = url.substring(index + 1);
bool base64 = mediaType.endsWith(";base64", false);
if (base64)
mediaType = mediaType.left(mediaType.length() - 7);
if (mediaType.isEmpty())
mediaType = "text/plain";
String mimeType = extractMIMETypeFromMediaType(mediaType);
String charset = extractCharsetFromMediaType(mediaType);
if (charset.isEmpty())
charset = "US-ASCII";
ResourceResponse response;
response.setMimeType(mimeType);
response.setTextEncodingName(charset);
response.setURL(handle->firstRequest().url());
if (base64) {
data = decodeURLEscapeSequences(data);
handle->client()->didReceiveResponse(handle, response);
Vector<char> out;
if (base64Decode(data, out, IgnoreWhitespace) && out.size() > 0) {
response.setExpectedContentLength(out.size());
handle->client()->didReceiveData(handle, out.data(), out.size(), 0);
}
} else {
TextEncoding encoding(charset);
data = decodeURLEscapeSequences(data, encoding);
handle->client()->didReceiveResponse(handle, response);
CString encodedData = encoding.encode(data.characters(), data.length(), URLEncodedEntitiesForUnencodables);
response.setExpectedContentLength(encodedData.length());
if (encodedData.length())
handle->client()->didReceiveData(handle, encodedData.data(), encodedData.length(), 0);
}
handle->client()->didFinishLoading(handle, 0);
}
示例15: stringToReproduceMap
std::unordered_map<std::string, Reproduce>
stringToReproduceMap(const std::string &str) {
const auto data = base64Decode(str);
std::unordered_map<std::string, Reproduce> reproduceMap;
try {
deserialize(begin(data), end(data), reproduceMap);
} catch (const SerializationException &) {
throw ParseException(0, "Invalid format");
}
return reproduceMap;
}