コード例 #1
0
 private static void test(PrivateKey privateKey, PublicKey publicKey) throws Exception {
   testSignature("MD2withRSA", privateKey, publicKey);
   testSignature("MD5withRSA", privateKey, publicKey);
   testSignature("SHA1withRSA", privateKey, publicKey);
   testSignature("SHA224withRSA", privateKey, publicKey);
   testSignature("SHA256withRSA", privateKey, publicKey);
   RSAPublicKey rsaKey = (RSAPublicKey) publicKey;
   if (rsaKey.getModulus().bitLength() > 512) {
     // for SHA384 and SHA512 the data is too long for 512 bit keys
     testSignature("SHA384withRSA", privateKey, publicKey);
     testSignature("SHA512withRSA", privateKey, publicKey);
   }
 }
コード例 #2
0
ファイル: KEYConverter.java プロジェクト: lemmy/dnsjava
  static byte[] buildRSA(RSAPublicKey key) {
    DataByteOutputStream out = new DataByteOutputStream();
    BigInteger exponent = key.getPublicExponent();
    BigInteger modulus = key.getModulus();
    int exponentLength = BigIntegerLength(exponent);

    if (exponentLength < 256) out.writeByte(exponentLength);
    else {
      out.writeByte(0);
      out.writeShort(exponentLength);
    }
    out.writeBigInteger(exponent);
    out.writeBigInteger(modulus);

    return out.toByteArray();
  }