| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.security.keystore2; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.security.KeyStoreSecurityLevel; |
| 21 |
import android.security.keystore.KeyProperties; |
| 22 |
import android.system.keystore2.KeyDescriptor; |
| 23 |
import android.system.keystore2.KeyMetadata; |
| 24 |
|
| 25 |
import java.math.BigInteger; |
| 26 |
import java.security.interfaces.RSAPublicKey; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class AndroidKeyStoreRSAPublicKey extends AndroidKeyStorePublicKey implements RSAPublicKey { |
| 34 |
private final BigInteger mModulus; |
| 35 |
private final BigInteger mPublicExponent; |
| 36 |
|
| 37 |
public AndroidKeyStoreRSAPublicKey(@NonNull KeyDescriptor descriptor, |
| 38 |
@NonNull KeyMetadata metadata, |
| 39 |
@NonNull byte[] x509EncodedForm, |
| 40 |
@NonNull KeyStoreSecurityLevel securityLevel, @NonNull BigInteger modulus, |
| 41 |
@NonNull BigInteger publicExponent) { |
| 42 |
super(descriptor, metadata, x509EncodedForm, KeyProperties.KEY_ALGORITHM_RSA, |
| 43 |
securityLevel); |
| 44 |
mModulus = modulus; |
| 45 |
mPublicExponent = publicExponent; |
| 46 |
} |
| 47 |
|
| 48 |
public AndroidKeyStoreRSAPublicKey(@NonNull KeyDescriptor descriptor, |
| 49 |
@NonNull KeyMetadata metadata, |
| 50 |
@NonNull KeyStoreSecurityLevel securityLevel, @NonNull RSAPublicKey info) { |
| 51 |
this(descriptor, metadata, info.getEncoded(), securityLevel, info.getModulus(), |
| 52 |
info.getPublicExponent()); |
| 53 |
if (!"X.509".equalsIgnoreCase(info.getFormat())) { |
| 54 |
throw new IllegalArgumentException( |
| 55 |
"Unsupported key export format: " + info.getFormat()); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public AndroidKeyStorePrivateKey getPrivateKey() { |
| 61 |
return new AndroidKeyStoreRSAPrivateKey(getUserKeyDescriptor(), getKeyIdDescriptor().nspace, |
| 62 |
getAuthorizations(), getSecurityLevel(), mModulus); |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public BigInteger getModulus() { |
| 67 |
return mModulus; |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public BigInteger getPublicExponent() { |
| 72 |
return mPublicExponent; |
| 73 |
} |
| 74 |
} |