Constructs an RSAPublicKey object.
if (! (keySpec instanceof X509EncodedKeySpec)) {
throw new InvalidKeySpecException();
}
this.keySpec = (X509EncodedKeySpec) keySpec;
byte[] data = getEncoded();
/*
* SubjectPublicKeyInfo { ALGORITHM : IOSet} ::= SEQUENCE {
* algorithm AlgorithmIdentifier {{IOSet}},
* subjectPublicKey BIT STRING
* }
*
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL
* }
*
*/
try {
TLV t = new TLV(data, 0);
t = t.child; // AlgorithmIdentifier
if (! Utils.byteMatch(data, t.child.valueOffset, t.child.length,
RSA_OID, 0, RSA_OID.length)) {
throw new InvalidKeySpecException(
"Invalid algorithm identifier");
}
t = t.next; // subjectPublicKey
/*
* RSAPublicKey ::= SEQUENCE {
* modulus INTEGER, -- n
* publicExponent INTEGER -- e --
* }
*/
// the first byte of value in BIT STRING is the number of
// unused bits
t = new TLV(data, t.valueOffset + 1);
t = t.child; // modulus
int offset = t.valueOffset;
int len = t.length;
while (data[offset] == 0) {
offset++;
len--;
}
keyLen = ((len + 7) / 8) * 8;
t = t.next;
key = new com.sun.midp.crypto.RSAPublicKey(data, offset, len,
data, t.valueOffset, t.length);
} catch (InvalidKeySpecException ikse) {
throw ikse;
} catch (NullPointerException npe) {
throw new InvalidKeySpecException();
} catch (TLVException tlve) {
throw new InvalidKeySpecException();
}