Java Key Pair Create generateKeyZ(ECPrivateKey privateKey, ECPublicKey publicKey)

Here you can find the source of generateKeyZ(ECPrivateKey privateKey, ECPublicKey publicKey)

Description

generate Key Z

License

Apache License

Declaration

private static byte[] generateKeyZ(ECPrivateKey privateKey,
            ECPublicKey publicKey) 

Method Source Code

//package com.java2s;
/**/*from   w  ww .j  a  v  a 2s  .  com*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;

import javax.crypto.KeyAgreement;

public class Main {
    private static byte[] generateKeyZ(ECPrivateKey privateKey,
            ECPublicKey publicKey) {
        try {
            KeyAgreement ka = KeyAgreement.getInstance("ECDH");
            ka.init(privateKey);
            ka.doPhase(publicKey, true);
            return ka.generateSecret();
        } catch (Exception ex) {
            throw new SecurityException(ex);
        }
    }
}

Related

  1. generateKeyPair(String algorithm, int size)
  2. generateKeyPair(String keyAlgorithm, int keySize)
  3. generateKeyPair(String type, int size)
  4. generateKeys(int size)
  5. generateKeyStoreFromPEM(File certFile, File keyFile)