package tv.ouya.console.api;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.util.Base64;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class Purchasable
  implements Parcelable
{
  public static final Parcelable.Creator<Purchasable> CREATOR = new Parcelable.Creator()
  {
    public Purchasable createFromParcel(Parcel paramAnonymousParcel)
    {
      String str = paramAnonymousParcel.readString();
      switch (paramAnonymousParcel.readByte())
      {
      default: 
        throw new IllegalArgumentException("Unable to rebuild purchasable. Encryption data state unknown");
      case 1: 
        return new Purchasable(str);
      }
      return new Purchasable(str, paramAnonymousParcel.readString(), paramAnonymousParcel.readString(), paramAnonymousParcel.readString());
    }
    
    public Purchasable[] newArray(int paramAnonymousInt)
    {
      return new Purchasable[paramAnonymousInt];
    }
  };
  private String mIV;
  private String mKey;
  private String mPayload;
  private String productId;
  
  public Purchasable(String paramString)
  {
    this.productId = paramString;
  }
  
  public Purchasable(String paramString1, String paramString2, String paramString3, String paramString4)
  {
    this.productId = paramString1;
    this.mKey = paramString2;
    this.mIV = paramString3;
    this.mPayload = paramString4;
  }
  
  private boolean encrypt(PublicKey paramPublicKey)
    throws GeneralSecurityException, UnsupportedEncodingException
  {
    Object localObject2 = SecureRandom.getInstance("SHA1PRNG");
    byte[] arrayOfByte1 = new byte[16];
    ((SecureRandom)localObject2).nextBytes(arrayOfByte1);
    Object localObject1 = new SecretKeySpec(arrayOfByte1, "AES");
    byte[] arrayOfByte2 = new byte[16];
    ((SecureRandom)localObject2).nextBytes(arrayOfByte2);
    localObject2 = new IvParameterSpec(arrayOfByte2);
    Cipher localCipher = Cipher.getInstance("AES");
    localCipher.init(1, (Key)localObject1, (AlgorithmParameterSpec)localObject2);
    localObject1 = localCipher.doFinal(this.productId.getBytes("UTF-8"));
    localObject2 = Cipher.getInstance("RSA");
    ((Cipher)localObject2).init(1, paramPublicKey);
    this.mKey = Base64.encodeToString(((Cipher)localObject2).doFinal(arrayOfByte1), 0);
    this.mIV = Base64.encodeToString(arrayOfByte2, 0);
    this.mPayload = Base64.encodeToString((byte[])localObject1, 0);
    return true;
  }
  
  public int describeContents()
  {
    return 0;
  }
  
  public boolean equals(Object paramObject)
  {
    if (this == paramObject) {
      return true;
    }
    if ((paramObject == null) || (getClass() != paramObject.getClass())) {
      return false;
    }
    paramObject = (Purchasable)paramObject;
    return this.productId.equals(((Purchasable)paramObject).productId);
  }
  
  public String getProductId()
  {
    return this.productId;
  }
  
  public boolean hasEncryptionParameters()
  {
    return (this.mKey != null) && (this.mIV != null) && (this.mPayload != null);
  }
  
  public int hashCode()
  {
    return this.productId.hashCode();
  }
  
  public String toJSON()
  {
    if (!hasEncryptionParameters()) {
      return null;
    }
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("{ \"key\" : \"");
    localStringBuilder.append(this.mKey);
    localStringBuilder.append("\", \"iv\" : \"");
    localStringBuilder.append(this.mIV);
    localStringBuilder.append("\", \"blob\" : \"");
    localStringBuilder.append(this.mPayload);
    localStringBuilder.append("\" }");
    return localStringBuilder.toString();
  }
  
  public void writeToParcel(Parcel paramParcel, int paramInt)
  {
    paramParcel.writeString(this.productId);
    if (hasEncryptionParameters())
    {
      paramParcel.writeByte((byte)2);
      paramParcel.writeString(this.mKey);
      paramParcel.writeString(this.mIV);
      paramParcel.writeString(this.mPayload);
      return;
    }
    paramParcel.writeByte((byte)1);
  }
}


/* Location:              /home/enzo/Documents/hacking/malwares/viking-horde/classes.jar!/tv/ouya/console/api/Purchasable.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */