我在 Android NDK 中遇到来自 OpenSSL 的 SHA512 的问题。我已经从 Guardianproject ( https://github.com/guardianproject/openssl-android ) 克隆并编译了 openssl android 版本,效果非常好。唯一的问题是 SHA512 无法正常工作。我使用 test_deviceid 作为输入字符串:
Nexus 4:
SHA 1: FzEeo2JrQQ6eYO7JedEOrMiki98=
SHA 256: 2+Bm6XrPgz6LeFb9PzqGMiAfaCaZqwmfJGQCJj8bbx8=
SHA 512: 6LbCI1ygLlLolo5sLDfypMmEODHHyBCe694HP6Tch6tE75vJ3nVAteXglDRS1TYhzXt4cBZkJaDK6tI+Ljgsvw==
Ubuntu commandline (also built from source):
SHA 1: FzEeo2JrQQ6eYO7JedEOrMiki98=
SHA 256: 2+Bm6XrPgz6LeFb9PzqGMiAfaCaZqwmfJGQCJj8bbx8=
SHA 512: dUqkGxOGS9+ZL89JOzFpNHNFokJ2ZqahDOp7ZxRfZ4eoF6B42icUvJW+/g7OA5pBWYkcpGUmZtg0lOg7SmrWJg==
//编辑:我调用的函数是来自 OpenSSL 库的 SHA512,可以在这里找到:https ://github.com/guardianproject/openssl-android/blob/master/crypto/sha/sha512.c#L294
unsigned char *deviceid = (unsigned char *)argv[6];
int deviceidLen = strlen(argv[6]);
unsigned char *deviceid64 = NULL;
int deviceid64Len = 0;
unsigned char *params = NULL;
int paramsLen = 0;
LOGD("input %s", deviceid);
paramsLen = 20;
params = (char*)malloc(paramsLen);
SHA1(deviceid, deviceidLen, params);
deviceid64 = base64_encode((const unsigned char*)params, paramsLen, &deviceid64Len);
LOGD("SHA 1: %s\n", deviceid64);
free(params);
free(deviceid64);
paramsLen = 32;
params = (char*)malloc(paramsLen);
SHA256(deviceid, deviceidLen, params);
deviceid64 = base64_encode((const unsigned char*)params, paramsLen, &deviceid64Len);
LOGD("SHA 256: %s\n", deviceid64);
free(params);
free(deviceid64);
LOGD("input %s", deviceid);
paramsLen = 64;
params = (char*)malloc(paramsLen);
SHA512(deviceid, deviceidLen, params);
deviceid64 = base64_encode((const unsigned char*)params, paramsLen, &deviceid64Len);
LOGD("SHA 512: %s\n", deviceid64);
free(params);
free(deviceid64);
可能是因为cpu(ARM)吗?可能缺少编译标志?希望有人可以帮助我-我需要它来进行签名检查算法。
谢谢,罗马