View Javadoc
1   /*
2    * Copyright 2012 Brian Matthews
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.btmatthews.maven.plugins.crx;
18  
19  import java.security.GeneralSecurityException;
20  import java.security.PrivateKey;
21  import java.security.PublicKey;
22  
23  /**
24   * Implementations sign byte arrays using public/private key pairs.
25   *
26   * @author <a href="mailto:brian@btmatthews.com">Brian Matthews</a>
27   * @since 1.1.0
28   */
29  public interface SignatureHelper {
30  
31      /**
32       * Generate the signature for a byte array using the private key.
33       *
34       * @param data The byte array.
35       * @param key  private key.
36       * @return The signature as a byte array.
37       * @throws GeneralSecurityException If there was a error generating the signature.
38       */
39      byte[] sign(byte[] data, PrivateKey key) throws GeneralSecurityException;
40  
41      /**
42       * Check that the signature is valid using the public key.
43       *
44       * @param data      The data for which the signature was generated.
45       * @param key       The public key.
46       * @param signature The signature.
47       * @return {@code true} if the signature was valid. Otherwise, {@code false}.
48       * @throws GeneralSecurityException If there was an error validating the signature.
49       */
50      boolean check(byte[] data, PublicKey key, byte[] signature) throws
51              GeneralSecurityException;
52  }