简体   繁体   English

Google Play商店应用内结算

[英]Google play store in-app billing

I've recently developed an app that I am soon to put on the Google play store. 我最近开发了一个应用程序,很快就会投放到Google Play商店中。 In this app I plan on adding one in-app purchase that once purchased allows the user to change colour settings(background & text). 在这个应用程序中,我计划添加一次应用程序内购买,一旦购买该应用程序,用户就可以更改颜色设置(背景和文字)。

I realised that checking the Google play store is unnecessary every time the application runs, especially if the purchase has been made already.It may also cause a problem if the user doesn't have GPRS/Wifi when using the app! 我意识到,每次运行应用程序时都不需要检查Google Play商店,尤其是已经购买了商品时,如果用户在使用该应用程序时没有GPRS / Wifi,这也可能会引起问题!

I was therefore thinking about creating a shared preference which would act as the condition to check whether the user has purchased the in-app purchase. 因此,我正在考虑创建一个共享首选项,该共享首选项将成为检查用户是否已购买应用程序内购买的条件。

Is there any other way that is maybe more secure? 还有其他方法可能更安全吗? as I've read shared preferences can be altered quite easily. 如我所读,共享首选项可以很容易地更改。

Any advice or suggestions would be appreciated. 任何意见或建议,将不胜感激。

You may use ProGuard . 您可以使用ProGuard

Or you can save purchased status in secure way using some Encrypted text either in shared preference or in database. 或者,您可以使用共享首选项或数据库中的某些加密文本以安全的方式保存购买状态。 So it gets harder to manipulate it. 因此,变得越来越难操纵它。

Encryption example: 加密示例:

Encrypt: 加密:

 MCrypt mcrypt = new MCrypt();
 String encrypted = MCrypt.bytesToHex(mcrypt.encrypt("Text to Encrypt"));

Decrypt: 解密:

MCrypt mcrypt = new MCrypt();
String decrypted = new String(mcrypt.decrypt(encrypted));

Mcrypt.java Mcrypt.java

public class MCrypt {

    private String iv = "fedcba9876543210";//Dummy iv (CHANGE IT!)
    private IvParameterSpec ivspec;
    private SecretKeySpec keyspec;
    private Cipher cipher;
    private String SecretKey = "0123456789abcdef";//Dummy secretKey (CHANGE IT!)

    public MCrypt() {
        ivspec = new IvParameterSpec(iv.getBytes());

        keyspec = new SecretKeySpec(SecretKey.getBytes(), "AES");

        try {
            cipher = Cipher.getInstance("AES/CBC/NoPadding");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        }
    }

    public byte[] encrypt(String text) throws Exception {
        if (text == null || text.length() == 0) throw new Exception("Empty string");

        byte[] encrypted = null;

        cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);

        encrypted = cipher.doFinal(padString(text).getBytes());
        try { 
            encrypted = android.util.Base64.encode(encrypted, android.util.Base64.NO_PADDING);
        } catch (NoClassDefFoundError e) {
        }

        return encrypted;
    }

    public byte[] decrypt(String code) throws Exception {
        if (code == null || code.length() == 0) throw new Exception("Empty string");

        byte[] decrypted = null;

        cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);

        try { 
            decrypted = cipher.doFinal(android.util.Base64.decode(code, android.util.Base64.NO_PADDING));
        } catch (NoClassDefFoundError e) {
        }
        return decrypted;
    }



    private static String padString(String source) {
        char paddingChar = ' ';
        int size = 16;
        int x = source.length() % size;
        int padLength = size - x;

        for (int i = 0; i < padLength; i++) {
            source += paddingChar;
        }

        return source;
    }
}

Reference: 参考:

128 bit encryption 128位加密

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM