我们正在使用WL.EncryptedCache.open打开本地存储。这有时需要4-8秒来获得加密密钥。请建议如何解决此性能问题?我们使用的是Worklight 6.0
发布于 2014-05-29 06:34:52
您可以通过覆盖安全随机调用WL.EncryptedCache.secureRandom = function(callback){callback(Math.random()+"")}
在本地生成安全令牌。这样你就不需要点击服务器来获取它了。这将大大降低安全性,我不推荐它。除此之外,在速度更快的设备上运行应用程序,您也无能为力。生成安全密钥是一项代价高昂的操作。
或者,您可以将上面的Math.random
替换为一个cordova插件exec
调用,该调用使用SecRandomCopyBytes获取加密安全的随机字符串。一些示例代码:
int bytes = 32;
uint8_t randBytes[bytes];
int rc = SecRandomCopyBytes(kSecRandomDefault, (size_t)bytes, randBytes);
if (rc != 0) {
//handle failure
}
NSMutableString* hexEncoded = [NSMutableString new];
for (int i = 0; i < bytes; i++) {
[hexEncoded appendString:[NSString stringWithFormat:@"%02x", randBytes[i]]];
}
NSString* randomStr = [NSString stringWithFormat:@"%@", hexEncoded];
有一些入门模块解释了如何为iOS here编写cordova插件。
https://stackoverflow.com/questions/23922508
复制相似问题