Beispiel #1
0
  /**
   * Sign a file.
   *
   * @param keyId the key id
   * @param fileName the file name
   * @throws Exception if an error occurs
   */
  @Command(description = "Sign a file")
  public void signFile(
      @Param(name = "keyId", description = "Key ID") String keyId,
      @Param(name = "fileName", description = "File name") String fileName)
      throws Exception {
    String algorithm = "SHA512withRSA";
    byte[] digest = calculateDigest(getDigestAlgorithmId(algorithm), fileToBytes(fileName));

    SignResponse response = SignerClient.execute(new Sign(keyId, algorithm, digest));
    System.out.println("Signature: " + Arrays.toString(response.getSignature()));
  }
Beispiel #2
0
 /**
  * Sign some data
  *
  * @param keyId the key id
  * @param data the data
  * @throws Exception if an error occurs
  */
 @Command(description = "Sign some data")
 public void sign(
     @Param(name = "keyId", description = "Key ID") String keyId,
     @Param(name = "data", description = "Data to sign (<data1> <data2> ...)") String... data)
     throws Exception {
   String algorithm = "SHA512withRSA";
   for (String d : data) {
     byte[] digest =
         calculateDigest(getDigestAlgorithmId(algorithm), d.getBytes(StandardCharsets.UTF_8));
     SignResponse response = SignerClient.execute(new Sign(keyId, algorithm, digest));
     System.out.println("Signature: " + Arrays.toString(response.getSignature()));
   }
 }