【发布时间】:2011-03-26 05:38:40
【问题描述】:
android 开发者网站上的示例应用程序使用 java 代码验证购买 json。有没有人幸运地解决了如何在 python 中验证购买。尤其是在 GAE 中?
以下是android应用内计费example program的相关摘录。这是需要使用PyCrypto 转换为python 的内容,该PyCrypto 被Google 重写为完全python,并且是应用程序引擎上唯一可用的安全库。希望谷歌对我使用下面的摘录很酷。
private static final String KEY_FACTORY_ALGORITHM = "RSA";
private static final String SIGNATURE_ALGORITHM = "SHA1withRSA";
String base64EncodedPublicKey = "your public key here";
PublicKey key = Security.generatePublicKey(base64EncodedPublicKey);
verified = Security.verify(key, signedData, signature);
public static PublicKey generatePublicKey(String encodedPublicKey) {
try {
byte[] decodedKey = Base64.decode(encodedPublicKey);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
} catch ...
}
}
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
if (Consts.DEBUG) {
Log.i(TAG, "signature: " + signature);
}
Signature sig;
try {
sig = Signature.getInstance(SIGNATURE_ALGORITHM);
sig.initVerify(publicKey);
sig.update(signedData.getBytes());
if (!sig.verify(Base64.decode(signature))) {
Log.e(TAG, "Signature verification failed.");
return false;
}
return true;
} catch ...
}
return false;
}
【问题讨论】:
-
我不打算将其发布为答案,因为我无法判断它是否是您正在寻找的确切内容,但试试这个link - Google Code,它展示了如何编写一个 GAE 应用程序,它将用 JSON 响应,我想你可以修改它以提供验证
标签: python android google-app-engine in-app-purchase