title: License Verification Library in Wallpaper
body: <p>I am currently trying to implement Google's LVL into my wallpaper but seem to have run into an issue with an exception I am not familiar with. I found this Question which helped me greatly, <a href="https://stackoverflow.com/questions/5348664/lvl-licensing-in-a-live-wallpaper">LVL licensing in a Live Wallpaper?</a>. One of the suggestions is to place code within the Engine and I opted to place it in the Class above. The code seems to compile fine but on run time I get an exception, apparently for my Public Key.</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to create service &lt;my package&gt;.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.&lt;init&gt;(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
  </code></pre>
  
  <p>Here is the code that I use:</p>
  
  <pre><code>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[] {&lt;20 random int&gt;};
  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 {
           &lt;Unrelevant code removed&gt;
  }
  
  @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
  
  }
  
  }
  </code></pre>
  
  <p>Is there a certain way I should format my public key or is it something entirely different?</p>
  
  <p>The exception comes from : mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, aes), BASE64_PUBLIC_KEY);</p>
  
  <p>Any advice would be greatly appreciated.</p>