RSAKeypublic class RSAKey extends Object implements KeyImplements RSAKey with methods to set and get RSA exponent
and modulus. |
Fields Summary |
---|
byte[] | expLocal variable to hold the exponent. | byte[] | modThe number of bytes allocated to the modulus
is always a multiple of 8. |
Constructors Summary |
---|
RSAKey(byte[] modulus, int modOffset, int modLen, byte[] exponent, int expOffset, int expLen)Constructor for RSA public key.
setModulus(modulus, modOffset, modLen);
setExponent(exponent, expOffset, expLen);
|
Methods Summary |
---|
public boolean | equals(RSAPrivateKey k)Compare the current key as a RSA private key.
return equals((RSAKey) k);
| public boolean | equals(RSAPublicKey k)Compare the current key as a RSA public key.
return equals((RSAKey) k);
| public boolean | equals(com.sun.midp.crypto.RSAKey k)Compare the current key as a generic RSA key.
byte[] kexp = new byte[exp.length];
byte[] kmod = new byte[mod.length];
if (this.getClass() != k.getClass())
return false;
if (k.getExponent(kexp, (short) 0) != exp.length)
return false;
if (k.getModulus(kmod, (short) 0) != mod.length)
return false;
for (int i = 0; i < exp.length; i++)
if (kexp[i] != exp[i])
return false;
for (int i = 0; i < mod.length; i++)
if (kmod[i] != mod[i])
return false;
return true;
| public java.lang.String | getAlgorithm()Gets the type of the current key.
return "RSA";
| public byte[] | getEncoded()Returns the encoding of key.
return null;
| public short | getExponent(byte[] buf, short off)Get the exponent for the key.
if (off + exp.length > buf.length)
return 0;
System.arraycopy(exp, 0, buf, off, exp.length);
return ((short) exp.length);
| public java.lang.String | getFormat()Returns the name of the encoding format for this key.
return "RAW";
| public short | getModulus(byte[] buf, short off)Get the modulus for the key.
if (off + mod.length > buf.length)
return ((short) 0);
System.arraycopy(mod, 0, buf, off, mod.length);
return ((short) mod.length);
| public int | getModulusLen()Get the length of modulus for the key.
return mod.length;
| private void | setExponent(byte[] buf, int off, int len)Set the exponent for the key.
exp = new byte[len];
System.arraycopy(buf, off, exp, 0, len);
| private void | setModulus(byte[] buf, int off, int len)Set the modulus for the key.
// move modulus len out to a multiple of 64 bits (8 bytes)
len = (len + 7) / 8 * 8;
mod = new byte[len];
System.arraycopy(buf, off, mod, 0, len);
| public java.lang.String | toString()Convert the key to a readable string.
return ("[" + (getModulusLen() * 8) + "-bit RSA key" +
", Exponent: 0x" + Util.hexEncode(exp) +
", Modulus: 0x" + Util.hexEncode(mod) + "]");
|
|