壁纸中的许可证验证库

时间:2011-06-06 16:25:03

标签: android live-wallpaper android-lvl

我目前正在尝试将Google的LVL应用到我的壁纸中,但似乎遇到了一个我不熟悉的例外问题。我发现这个问题对我很有帮助,LVL licensing in a Live Wallpaper?。其中一个建议是在Engine中放置代码,我选择将其放在上面的Class中。代码似乎编译正常,但在运行时我得到一个例外,显然是我的公钥。

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to create service <my package>.MyWallpaper: java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.io.IOException: corrupted stream - out of bounds length found
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2076)
at android.app.ActivityThread.access$2500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.io.IOException: corrupted stream - out of bounds length found
at com.android.vending.licensing.LicenseChecker.generatePublicKey(LicenseChecker.java:121)
at com.android.vending.licensing.LicenseChecker.<init>(LicenseChecker.java:92)
at com.metastable.epicvis.vis1.ScopeVisualizer.onCreate(ScopeVisualizer.java:41)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2066)
... 10 more
Caused by: java.security.spec.InvalidKeySpecException: java.io.IOException: corrupted stream - out of bounds length found
at org.bouncycastle.jce.provider.JDKKeyFactory.engineGeneratePublic(JDKKeyFactory.java:92)
at org.bouncycastle.jce.provider.JDKKeyFactory$RSA.engineGeneratePublic(JDKKeyFactory.java:396)
at java.security.KeyFactory.generatePublic(KeyFactory.java:177)
at com.android.vending.licensing.LicenseChecker.generatePublicKey(LicenseChecker.java:112)
... 13 more

以下是我使用的代码:

public class MyWallpaper extends WallpaperService implements LicenseCheckerCallback {

private LicenseChecker mChecker;
private static final String BASE64_PUBLIC_KEY = "My public key from google"; 
private byte[] salt = new byte[] {<20 random int>};
private String deviceId;
private AESObfuscator aes;


@Override
public void onCreate() {
    super.onCreate();
    deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    aes = new AESObfuscator(salt, getPackageName(), deviceId);
    mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, aes), BASE64_PUBLIC_KEY);
    mChecker.checkAccess(this);
}

@Override
public void onDestroy() {
    super.onDestroy();
    mChecker.onDestroy();
}

@Override
public Engine onCreateEngine() {
    return new VisualizerEngine();
}

class MyEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
         <Unrelevant code removed>
}

@Override
public void allow() {
    Toast.makeText(this, "Allowed", Toast.LENGTH_SHORT);

}

@Override
public void dontAllow() {
    Toast.makeText(this, "Not Allowed", Toast.LENGTH_SHORT);

}

@Override
public void applicationError(ApplicationErrorCode errorCode) {
    // TODO Auto-generated method stub

}

}

我应该以某种方式格式化我的公钥,还是完全不同?

例外来自:mChecker = new LicenseChecker(this,new ServerManagedPolicy(this,aes),BASE64_PUBLIC_KEY);

非常感谢任何建议。

1 个答案:

答案 0 :(得分:1)

我已经弄明白了这个问题,显然我很糟糕,复制和粘贴。而不是单击拖动并选择我的键,我做了很多次并继续失败,我只是三次点击并正确复制。嘿。