问题描述
Google Chrome浏览器正在使用字母数字哈希值作为Chrome扩展程序的标识符。例如。 ajpgkpeckebdhofmmjfgcjjiiejpodla是书签同步扩展程序的标识符。这里使用哪种算法来生成这样的字符串?他们如何确保独特性?
Chromium通过公钥生成id。如果您使用扩展程序库,它们会处理所有这些内容。
从 看看extension.cc文件,它有更详细的信息,例如生成.pem文件的exncoding /解码等。 Google Chrome is using alpha numeric hashes as identifiers for the Chrome extensions. For eg. "ajpgkpeckebdhofmmjfgcjjiiejpodla" is the identifier for XMarks Bookmark Sync extension. Which algorithm is in use here to generate such strings? How are they ensuring uniqueness? Chromium generates the id via public key. If you use the extension gallery, they handle all that for you. From the source: Take a look at extension.cc file it has more detailed information such as generating the .pem file exncoding/decoding, etc. 这篇关于谷歌浏览器 - 字母数字哈希标识扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! bool Extension :: GenerateId(const std :: string& input,std :: string * output){
CHECK(output);
if(input.length()== 0)
return false;
$ b $ const uint8 * ubuf = reinterpret_cast< const unsigned char *>(input.data());
SHA256Context ctx;
SHA256_Begin(& ctx);
SHA256_Update(& ctx,ubuf,input.length());
uint8 hash [Extension :: kIdSize];
SHA256_End(& ctx,hash,NULL,sizeof(hash));
* output = StringToLowerASCII(HexEncode(hash,sizeof(hash)));
ConvertHexadecimalToIDAlphabet(output);
返回true;
}
bool Extension::GenerateId(const std::string& input, std::string* output) {
CHECK(output);
if (input.length() == 0)
return false;
const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data());
SHA256Context ctx;
SHA256_Begin(&ctx);
SHA256_Update(&ctx, ubuf, input.length());
uint8 hash[Extension::kIdSize];
SHA256_End(&ctx, hash, NULL, sizeof(hash));
*output = StringToLowerASCII(HexEncode(hash, sizeof(hash)));
ConvertHexadecimalToIDAlphabet(output);
return true;
}