下面列出了怎么用java.security.spec.RSAOtherPrimeInfo的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Test #11 for
* <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus,
* BigInteger publicExponent,
* BigInteger privateExponent,
* BigInteger primeP,
* BigInteger primeQ,
* BigInteger primeExponentP,
* BigInteger primeExponentQ,
* BigInteger crtCoefficient,
* RSAOtherPrimeInfo[] otherPrimeInfo)
* </code> ctor<br>
* Assertion: IllegalArgumentException if otherPrimeInfo length is 0
*/
public final void testRSAMultiPrimePrivateCrtKeySpec11() {
try {
new RSAMultiPrimePrivateCrtKeySpec(
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
new RSAOtherPrimeInfo[0]);
fail("Expected IAE not thrown");
} catch (IllegalArgumentException e) {
}
}
/**
* Tests that internal state of the object
* can not be modified by modifying initial array
*/
public final void testIsStatePreserved1() {
// Create initial array
RSAOtherPrimeInfo[] opi1 = opi.clone();
RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec(
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
opi1);
// Modify initial array
opi1[2] = new RSAOtherPrimeInfo(BigInteger.ZERO,
BigInteger.ZERO,
BigInteger.ZERO);
// Check that above modification
// does not affect internal state
assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo()));
}
private static RsaPrivateKeyDef from(RSAMultiPrimePrivateCrtKey key) {
FingerTrieSeq<RsaPrimeDef> primeDefs = FingerTrieSeq.empty();
primeDefs = primeDefs.appended(new RsaPrimeDef(key.getPrimeP(), key.getPrimeExponentP()));
primeDefs = primeDefs.appended(new RsaPrimeDef(key.getPrimeQ(), key.getPrimeExponentQ(), key.getCrtCoefficient()));
final RSAOtherPrimeInfo[] otherPrimes = key.getOtherPrimeInfo();
for (int i = 0, n = otherPrimes.length; i < n; i += 1) {
primeDefs = primeDefs.appended(RsaPrimeDef.from(otherPrimes[i]));
}
return new RsaPrivateKeyDef(key.getModulus(), key.getPublicExponent(), key.getPrivateExponent(), primeDefs, key);
}
/**
* Test #1 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
* Assertion: constructs <code>RSAOtherPrimeInfo</code>
* object using valid parameter
*/
public final void testRSAOtherPrimeInfo01() {
Object o =
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
BigInteger.valueOf(2L),
BigInteger.valueOf(3L));
assertTrue(o instanceof RSAOtherPrimeInfo);
}
/**
* Test #2 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
* Assertion: NullPointerException if prime is null
*/
public final void testRSAOtherPrimeInfo02() {
try {
new RSAOtherPrimeInfo(null,
BigInteger.valueOf(2L),
BigInteger.valueOf(3L));
fail("Expected NPE not thrown");
} catch (NullPointerException e) {
}
}
/**
* Test #3 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
* Assertion: NullPointerException if primeExponent is null
*/
public final void testRSAOtherPrimeInfo03() {
try {
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
null,
BigInteger.valueOf(3L));
fail("Expected NPE not thrown");
} catch (NullPointerException e) {
}
}
/**
* Test #4 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
* Assertion: NullPointerException if crtCoefficient is null
*/
public final void testRSAOtherPrimeInfo04() {
try {
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
BigInteger.valueOf(2L),
null);
fail("Expected NPE not thrown");
} catch (NullPointerException e) {
}
}
/**
* Test #5 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
* Assertion: NullPointerException if prime and crtCoefficient is null
*/
public final void testRSAOtherPrimeInfo05() {
try {
new RSAOtherPrimeInfo(null,
BigInteger.valueOf(2L),
null);
fail("Expected NPE not thrown");
} catch (NullPointerException e) {
}
}
/**
* Test for <code>getCrtCoefficient()</code> method<br>
* Assertion: returns CRT coefficient value
*/
public final void testGetCrtCoefficient() {
RSAOtherPrimeInfo ropi =
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
BigInteger.valueOf(2L),
BigInteger.valueOf(3L));
assertEquals(3L, ropi.getCrtCoefficient().longValue());
}
/**
* Test for <code>getPrime()</code> method<br>
* Assertion: returns prime value
*/
public final void testGetPrime() {
RSAOtherPrimeInfo ropi =
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
BigInteger.valueOf(2L),
BigInteger.valueOf(3L));
assertEquals(1L, ropi.getPrime().longValue());
}
/**
* Test for <code>getExponent()</code> method<br>
* Assertion: returns prime exponent value
*/
public final void testGetExponent() {
RSAOtherPrimeInfo ropi =
new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
BigInteger.valueOf(2L),
BigInteger.valueOf(3L));
assertEquals(2L, ropi.getExponent().longValue());
}
/**
* Tests that internal state of the object
* can not be modified using array reference
* returned by <code>getOtherPrimeInfo()</code>
* method
*/
public final void testIsStatePreserved2() {
// Create initial array
RSAOtherPrimeInfo[] opi1 = opi.clone();
RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec(
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
BigInteger.ONE,
opi1);
RSAOtherPrimeInfo[] ret = ks.getOtherPrimeInfo();
// Modify returned array
ret[2] = new RSAOtherPrimeInfo(BigInteger.ZERO,
BigInteger.ZERO,
BigInteger.ZERO);
// Check that above modification
// does not affect internal state
assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo()));
}
/**
* Compares array passed as a parameter with reference one<br>
*
* <code>private static final RSAOtherPrimeInfo[] opi</code>
*
* @param toBeChecked
* Array to be compared
* @return
* true if arrays are equal
*/
private boolean checkOtherPrimeInfo(RSAOtherPrimeInfo[] toBeChecked) {
if (toBeChecked == null || toBeChecked.length != opi.length) {
return false;
}
for (int i=0; i<opi.length; i++) {
if (opi[i].getPrime().equals(toBeChecked[i].getPrime()) &&
opi[i].getExponent().equals(toBeChecked[i].getExponent()) &&
opi[i].getCrtCoefficient().equals(toBeChecked[i].getCrtCoefficient())) {
continue;
}
return false;
}
return true;
}
public static RsaPrimeDef from(RSAOtherPrimeInfo info) {
return new RsaPrimeDef(info.getPrime(), info.getExponent(), info.getCrtCoefficient());
}
public final RSAOtherPrimeInfo toRSAOtherPrimeInfo() {
return new RSAOtherPrimeInfo(this.factor, this.exponent, this.coefficient);
}
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();
/**
* Returns the otherPrimeInfo or null if there are only
* two prime factors (p and q).
*
* @return the otherPrimeInfo.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo();