Example usage for org.bouncycastle.jce X509KeyUsage encipherOnly

List of usage examples for org.bouncycastle.jce X509KeyUsage encipherOnly

Introduction

In this page you can find the example usage for org.bouncycastle.jce X509KeyUsage encipherOnly.

Prototype

int encipherOnly

To view the source code for org.bouncycastle.jce X509KeyUsage encipherOnly.

Click Source Link

Usage

From source file:org.cesecore.util.CertTools.java

License:Open Source License

/**
 * Converts Sun Key usage bits to Bouncy castle key usage kits
 * /*ww  w  .j a  v  a  2s.c o  m*/
 * @param sku key usage bit fields according to java.security.cert.X509Certificate#getKeyUsage, must be a boolean aray of size 9.
 * @return key usage int according to org.bouncycastle.jce.X509KeyUsage#X509KeyUsage, or -1 if input is null.
 * @see java.security.cert.X509Certificate#getKeyUsage
 * @see org.bouncycastle.jce.X509KeyUsage#X509KeyUsage
 */
public static int sunKeyUsageToBC(boolean[] sku) {
    if (sku == null) {
        return -1;
    }
    int bcku = 0;
    if (sku[0]) {
        bcku = bcku | X509KeyUsage.digitalSignature;
    }
    if (sku[1]) {
        bcku = bcku | X509KeyUsage.nonRepudiation;
    }
    if (sku[2]) {
        bcku = bcku | X509KeyUsage.keyEncipherment;
    }
    if (sku[3]) {
        bcku = bcku | X509KeyUsage.dataEncipherment;
    }
    if (sku[4]) {
        bcku = bcku | X509KeyUsage.keyAgreement;
    }
    if (sku[5]) {
        bcku = bcku | X509KeyUsage.keyCertSign;
    }
    if (sku[6]) {
        bcku = bcku | X509KeyUsage.cRLSign;
    }
    if (sku[7]) {
        bcku = bcku | X509KeyUsage.encipherOnly;
    }
    if (sku[8]) {
        bcku = bcku | X509KeyUsage.decipherOnly;
    }
    return bcku;
}