コード例 #1
0
ファイル: IdentityManager.java プロジェクト: named-data/jndn
  /**
   * Append a SignatureInfo for DigestSha256 to the Interest name, digest the name components and
   * append a final name component with the signature bits (which is the digest).
   *
   * @param interest The Interest object to be signed. This appends name components of SignatureInfo
   *     and the signature bits.
   * @param wireFormat A WireFormat object used to encode the input.
   */
  public final void signInterestWithSha256(Interest interest, WireFormat wireFormat) {
    DigestSha256Signature signature = new DigestSha256Signature();
    // Append the encoded SignatureInfo.
    interest.getName().append(wireFormat.encodeSignatureInfo(signature));

    // Append an empty signature so that the "signedPortion" is correct.
    interest.getName().append(new Name.Component());
    // Encode once to get the signed portion.
    SignedBlob encoding = interest.wireEncode(wireFormat);

    // Digest and set the signature.
    byte[] signedPortionDigest = Common.digestSha256(encoding.signedBuf());
    signature.setSignature(new Blob(signedPortionDigest, false));

    // Remove the empty signature and append the real one.
    interest.setName(
        interest.getName().getPrefix(-1).append(wireFormat.encodeSignatureValue(signature)));
  }
コード例 #2
0
ファイル: IdentityManager.java プロジェクト: named-data/jndn
  /**
   * Append a SignatureInfo to the Interest name, sign the name components and append a final name
   * component with the signature bits.
   *
   * @param interest The Interest object to be signed. This appends name components of SignatureInfo
   *     and the signature bits.
   * @param certificateName The certificate name of the key to use for signing.
   * @param wireFormat A WireFormat object used to encode the input.
   */
  public final void signInterestByCertificate(
      Interest interest, Name certificateName, WireFormat wireFormat) throws SecurityException {
    DigestAlgorithm[] digestAlgorithm = new DigestAlgorithm[1];
    Signature signature = makeSignatureByCertificate(certificateName, digestAlgorithm);

    // Append the encoded SignatureInfo.
    interest.getName().append(wireFormat.encodeSignatureInfo(signature));

    // Append an empty signature so that the "signedPortion" is correct.
    interest.getName().append(new Name.Component());
    // Encode once to get the signed portion, and sign.
    SignedBlob encoding = interest.wireEncode(wireFormat);
    signature.setSignature(
        privateKeyStorage_.sign(
            encoding.signedBuf(),
            IdentityCertificate.certificateNameToPublicKeyName(certificateName),
            digestAlgorithm[0]));

    // Remove the empty signature and append the real one.
    interest.setName(
        interest.getName().getPrefix(-1).append(wireFormat.encodeSignatureValue(signature)));
  }