All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.worldpay.cse.jwe.WPKeyGen Maven / Gradle / Ivy

Go to download

Android SDK is a library created to help you integrate Worldpay client side encryption into your mobile applications.

There is a newer version: 1.0.4
Show newest version
package com.worldpay.cse.jwe;

import java.security.SecureRandom;
import java.util.Random;

/**
 * Key generator class
 *
 */
class WPKeyGen {

    private WPKeyGen() {
    }

    /**
     * The standard Initialisation Vector (IV) length (96 bits).
     */
    public static final int IV_BIT_LENGTH = 96;
    /**
     * The standard authentication tag length (128 bits).
     */
    public static final int AUTH_TAG_BIT_LENGTH = 128;
    /**
     * The standard key length (256 bits).
     */
    public static final int KEY_BIT_LENGTH = 256;

    private static Random randomGen = new SecureRandom();

    /**
     * Generate a key based on provided key size in bits
     *
     * @param keySize the size in bits
     * @return a byte array that represents they key
     */
    public static byte[] generateKey(int keySize) {
        byte[] bytes = new byte[keySize / 8];
        randomGen.nextBytes(bytes);
        return bytes;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy