谷歌浏览器 - 字母数字哈希标识扩展名 [英] Google Chrome - Alphanumeric hashes to identify extensions

查看:136
本文介绍了谷歌浏览器 - 字母数字哈希标识扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Chrome浏览器正在使用字母数字哈希值作为Chrome扩展程序的标识符。例如。 ajpgkpeckebdhofmmjfgcjjiiejpodla是 XMarks 书签同步扩展程序的标识符。



这里使用哪种算法来生成这样的字符串?他们如何确保独特性?

解决方案

Chromium通过公钥生成id。如果您使用扩展程序库,它们会处理所有这些内容。



   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;
}

看看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:

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;
}

Take a look at extension.cc file it has more detailed information such as generating the .pem file exncoding/decoding, etc.

这篇关于谷歌浏览器 - 字母数字哈希标识扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆