2011-06-06 224 views
1

我目前正試圖將Google的LVL應用到我的壁紙中,但似乎遇到了一個我並不熟悉的異常問題。我發現這個問題對我很有幫助,LVL licensing in a Live Wallpaper?。其中一個建議是將代碼放置在引擎中,並且我選擇將它放在上面的類中。代碼似乎編譯正常,但在運行時,我得到一個異常,顯然是我的公鑰。壁紙中的許可證驗證庫

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

我已經找到了這個問題,顯然我很糟糕,複製和粘貼。而不是點擊拖動和選擇我的密鑰,我做了很多次,並繼續失敗,我只需三次點擊,它複製正確。嘿。