安全性 - 在设备上实时生成 API 密钥
Security - Generate API Key in Real Time on Device
首先,我不确定在哪个 Stack Exchange 网站上询问这个问题,所以如果这是错误的,我深表歉意。
我阅读了 this 文章,其中讨论了在您的移动应用程序上存储 API 密钥的最安全方式,我感兴趣的方法之一是具有生成 API 密钥在本地并在服务器上具有相同的功能,这样就没有人可以破解您的代码并获得 API 密钥字符串文字。这正是文章所说的内容:
Your device does not need to store any kind of key and deal with all the hassle of protecting a String literal! This is a very old technique used by services such as remote key validation.
The client knows a function() that returns a key.
The backend knows the function() implemented in the client
The client generates a key through the function(), and this gets delivered to the server.
The server validates it, and proceeds with the request.
Are you connecting the dots? Instead of having a native function that returns you a string (easily identifiable) why not having a function that returns you the sum of three random prime numbers between 1 and 100? Or a function that takes the current day expressed in unixtime and adds a 1 to each different digit? What about taking some contextual information from the device, such as the amount of memory being used, to provide a higher degree of entropy?
现在我想知道的是,如何防止假想的黑客使用您用来获得有效 API 密钥的相同算法?在我看来,该函数看起来像这样(写在 javascript 中):
function generateKey() {
var key = 0
for(var i=0; i<4; i++) {
key *= Math.floor((Math.random() * 10) + 1);
}
return key // after encrypting it with unixtime as seed, for example
}
如果这个功能不能工作或者很愚蠢,请原谅,这只是字面意义上的第一个想到的事情。那么,黑客不能在对您的代码进行逆向工程后,按照相同的方法并提出一个服务器将标记为有效的密钥吗?
如果您想要 post 答案中的示例,请随意省略加密,因为我只需要简单的 'proof of concept' 答案。
谢谢
没有什么可以阻止攻击者这样做。如果攻击者可以对您的应用程序进行逆向工程,他们将找到您存储在其中的任何秘密。
本文的重点是如何让假设的逆向工程师尽可能难以真正找到您的秘密。这就是为什么在文章中,作者正在从 Java 方法(易于反编译)转移到本机方法(不那么容易反编译,但可以通过长的、看似随机的 API 键来识别他们正在使用) 到动态生成的密钥。
首先,我不确定在哪个 Stack Exchange 网站上询问这个问题,所以如果这是错误的,我深表歉意。
我阅读了 this 文章,其中讨论了在您的移动应用程序上存储 API 密钥的最安全方式,我感兴趣的方法之一是具有生成 API 密钥在本地并在服务器上具有相同的功能,这样就没有人可以破解您的代码并获得 API 密钥字符串文字。这正是文章所说的内容:
Your device does not need to store any kind of key and deal with all the hassle of protecting a String literal! This is a very old technique used by services such as remote key validation.
The client knows a function() that returns a key. The backend knows the function() implemented in the client The client generates a key through the function(), and this gets delivered to the server. The server validates it, and proceeds with the request. Are you connecting the dots? Instead of having a native function that returns you a string (easily identifiable) why not having a function that returns you the sum of three random prime numbers between 1 and 100? Or a function that takes the current day expressed in unixtime and adds a 1 to each different digit? What about taking some contextual information from the device, such as the amount of memory being used, to provide a higher degree of entropy?
现在我想知道的是,如何防止假想的黑客使用您用来获得有效 API 密钥的相同算法?在我看来,该函数看起来像这样(写在 javascript 中):
function generateKey() {
var key = 0
for(var i=0; i<4; i++) {
key *= Math.floor((Math.random() * 10) + 1);
}
return key // after encrypting it with unixtime as seed, for example
}
如果这个功能不能工作或者很愚蠢,请原谅,这只是字面意义上的第一个想到的事情。那么,黑客不能在对您的代码进行逆向工程后,按照相同的方法并提出一个服务器将标记为有效的密钥吗?
如果您想要 post 答案中的示例,请随意省略加密,因为我只需要简单的 'proof of concept' 答案。
谢谢
没有什么可以阻止攻击者这样做。如果攻击者可以对您的应用程序进行逆向工程,他们将找到您存储在其中的任何秘密。
本文的重点是如何让假设的逆向工程师尽可能难以真正找到您的秘密。这就是为什么在文章中,作者正在从 Java 方法(易于反编译)转移到本机方法(不那么容易反编译,但可以通过长的、看似随机的 API 键来识别他们正在使用) 到动态生成的密钥。