Java Code Examples for sun.security.krb5.internal.crypto.KeyUsage

The following examples show how to use sun.security.krb5.internal.crypto.KeyUsage. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: dragonwell8_jdk   Author: alibaba   File: KerberosPreMasterSecret.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor used by client to generate premaster secret.
 *
 * Client randomly creates a pre-master secret and encrypts it
 * using the Kerberos session key; only the server can decrypt
 * it, using the session key available in the service ticket.
 *
 * @param protocolVersion used to set preMaster[0,1]
 * @param generator random number generator for generating premaster secret
 * @param sessionKey Kerberos session key for encrypting premaster secret
 */
KerberosPreMasterSecret(ProtocolVersion protocolVersion,
    SecureRandom generator, EncryptionKey sessionKey) throws IOException {

    if (sessionKey.getEType() ==
        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
        throw new IOException(
           "session keys with des3-cbc-hmac-sha1-kd encryption type " +
           "are not supported for TLS Kerberos cipher suites");
    }

    this.protocolVersion = protocolVersion;
    preMaster = generatePreMaster(generator, protocolVersion);

    // Encrypt premaster secret
    try {
        EncryptedData eData = new EncryptedData(sessionKey, preMaster,
            KeyUsage.KU_UNKNOWN);
        encrypted = eData.getBytes();  // not ASN.1 encoded.

    } catch (KrbException e) {
        throw (SSLKeyException)new SSLKeyException
            ("Kerberos premaster secret error").initCause(e);
    }
}
 
Example #2
Source Project: hottub   Author: dsrg-uoft   File: KrbApRep.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void createMessage(
                           EncryptionKey key,
                           KerberosTime ctime,
                           int cusec,
                           EncryptionKey subKey,
                           SeqNumber seqNumber)
    throws Asn1Exception, IOException,
           KdcErrException, KrbCryptoException {

    Integer seqno = null;

    if (seqNumber != null)
        seqno = new Integer(seqNumber.current());

    encPart = new EncAPRepPart(ctime,
                               cusec,
                               subKey,
                               seqno);

    byte[] encPartEncoding = encPart.asn1Encode();

    EncryptedData encEncPart = new EncryptedData(key, encPartEncoding,
        KeyUsage.KU_ENC_AP_REP_PART);

    apRepMessg = new APRep(encEncPart);
}
 
Example #3
Source Project: dragonwell8_jdk   Author: alibaba   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs encryption of Sequence Number using derived key.
 */
public byte[] encryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    // derive encryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(plaintext, start, len);

    return output;
}
 
Example #4
Source Project: dragonwell8_jdk   Author: alibaba   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #5
Source Project: jdk8u-jdk   Author: frohoff   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs encryption of Sequence Number using derived key.
 */
public byte[] encryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    // derive encryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(plaintext, start, len);

    return output;
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: KerberosPreMasterSecret.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor used by client to generate premaster secret.
 *
 * Client randomly creates a pre-master secret and encrypts it
 * using the Kerberos session key; only the server can decrypt
 * it, using the session key available in the service ticket.
 *
 * @param protocolVersion used to set preMaster[0,1]
 * @param generator random number generator for generating premaster secret
 * @param sessionKey Kerberos session key for encrypting premaster secret
 */
KerberosPreMasterSecret(ProtocolVersion protocolVersion,
    SecureRandom generator, EncryptionKey sessionKey) throws IOException {

    if (sessionKey.getEType() ==
        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
        throw new IOException(
           "session keys with des3-cbc-hmac-sha1-kd encryption type " +
           "are not supported for TLS Kerberos cipher suites");
    }

    this.protocolVersion = protocolVersion;
    preMaster = generatePreMaster(generator, protocolVersion);

    // Encrypt premaster secret
    try {
        EncryptedData eData = new EncryptedData(sessionKey, preMaster,
            KeyUsage.KU_UNKNOWN);
        encrypted = eData.getBytes();  // not ASN.1 encoded.

    } catch (KrbException e) {
        throw (SSLKeyException)new SSLKeyException
            ("Kerberos premaster secret error").initCause(e);
    }
}
 
Example #7
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #8
Source Project: openjdk-8   Author: bpupadhyaya   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs encryption of Sequence Number using derived key.
 */
public byte[] encryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    // derive encryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(plaintext, start, len);

    return output;
}
 
Example #9
Source Project: jdk8u-dev-jdk   Author: frohoff   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs encryption of Sequence Number using derived key.
 */
public byte[] encryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    // derive encryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(plaintext, start, len);

    return output;
}
 
Example #10
Source Project: jdk8u60   Author: chenghanpeng   File: KrbApRep.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void createMessage(
                           EncryptionKey key,
                           KerberosTime ctime,
                           int cusec,
                           EncryptionKey subKey,
                           SeqNumber seqNumber)
    throws Asn1Exception, IOException,
           KdcErrException, KrbCryptoException {

    Integer seqno = null;

    if (seqNumber != null)
        seqno = new Integer(seqNumber.current());

    encPart = new EncAPRepPart(ctime,
                               cusec,
                               subKey,
                               seqno);

    byte[] encPartEncoding = encPart.asn1Encode();

    EncryptedData encEncPart = new EncryptedData(key, encPartEncoding,
        KeyUsage.KU_ENC_AP_REP_PART);

    apRepMessg = new APRep(encEncPart);
}
 
Example #11
Source Project: hottub   Author: dsrg-uoft   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #12
Source Project: jdk8u60   Author: chenghanpeng   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #13
Source Project: openjdk-8-source   Author: keerath   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #14
Source Project: openjdk-8   Author: bpupadhyaya   File: ArcFourCrypto.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs decryption of Sequence Number using derived key.
 */
public byte[] decryptSeq(byte[] baseKey, int usage,
    byte[] checksum, byte[] ciphertext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    // derive decryption for sequence number
    byte[] salt = new byte[4];
    byte[] kSeq = getHmac(baseKey, salt);

    // derive new encryption key salted with sequence number
    kSeq = getHmac(kSeq, checksum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kSeq, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #15
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: KrbApRep.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void createMessage(
                           EncryptionKey key,
                           KerberosTime ctime,
                           int cusec,
                           EncryptionKey subKey,
                           SeqNumber seqNumber)
    throws Asn1Exception, IOException,
           KdcErrException, KrbCryptoException {

    Integer seqno = null;

    if (seqNumber != null)
        seqno = seqNumber.current();

    encPart = new EncAPRepPart(ctime,
                               cusec,
                               subKey,
                               seqno);

    byte[] encPartEncoding = encPart.asn1Encode();

    EncryptedData encEncPart = new EncryptedData(key, encPartEncoding,
        KeyUsage.KU_ENC_AP_REP_PART);

    apRepMessg = new APRep(encEncPart);
}
 
Example #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: KrbApRep.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void createMessage(
                           EncryptionKey key,
                           KerberosTime ctime,
                           int cusec,
                           EncryptionKey subKey,
                           SeqNumber seqNumber)
    throws Asn1Exception, IOException,
           KdcErrException, KrbCryptoException {

    Integer seqno = null;

    if (seqNumber != null)
        seqno = new Integer(seqNumber.current());

    encPart = new EncAPRepPart(ctime,
                               cusec,
                               subKey,
                               seqno);

    byte[] encPartEncoding = encPart.asn1Encode();

    EncryptedData encEncPart = new EncryptedData(key, encPartEncoding,
        KeyUsage.KU_ENC_AP_REP_PART);

    apRepMessg = new APRep(encEncPart);
}
 
Example #17
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: KerberosPreMasterSecret.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor used by client to generate premaster secret.
 *
 * Client randomly creates a pre-master secret and encrypts it
 * using the Kerberos session key; only the server can decrypt
 * it, using the session key available in the service ticket.
 *
 * @param protocolVersion used to set preMaster[0,1]
 * @param generator random number generator for generating premaster secret
 * @param sessionKey Kerberos session key for encrypting premaster secret
 */
KerberosPreMasterSecret(ProtocolVersion protocolVersion,
    SecureRandom generator, EncryptionKey sessionKey) throws IOException {

    if (sessionKey.getEType() ==
        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
        throw new IOException(
           "session keys with des3-cbc-hmac-sha1-kd encryption type " +
           "are not supported for TLS Kerberos cipher suites");
    }

    this.protocolVersion = protocolVersion;
    preMaster = generatePreMaster(generator, protocolVersion);

    // Encrypt premaster secret
    try {
        EncryptedData eData = new EncryptedData(sessionKey, preMaster,
            KeyUsage.KU_UNKNOWN);
        encrypted = eData.getBytes();  // not ASN.1 encoded.

    } catch (KrbException e) {
        throw (SSLKeyException)new SSLKeyException
            ("Kerberos premaster secret error").initCause(e);
    }
}
 
Example #18
Source Project: jdk8u-jdk   Author: frohoff   File: KerberosPreMasterSecret.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor used by client to generate premaster secret.
 *
 * Client randomly creates a pre-master secret and encrypts it
 * using the Kerberos session key; only the server can decrypt
 * it, using the session key available in the service ticket.
 *
 * @param protocolVersion used to set preMaster[0,1]
 * @param generator random number generator for generating premaster secret
 * @param sessionKey Kerberos session key for encrypting premaster secret
 */
KerberosPreMasterSecret(ProtocolVersion protocolVersion,
    SecureRandom generator, EncryptionKey sessionKey) throws IOException {

    if (sessionKey.getEType() ==
        EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD) {
        throw new IOException(
           "session keys with des3-cbc-hmac-sha1-kd encryption type " +
           "are not supported for TLS Kerberos cipher suites");
    }

    this.protocolVersion = protocolVersion;
    preMaster = generatePreMaster(generator, protocolVersion);

    // Encrypt premaster secret
    try {
        EncryptedData eData = new EncryptedData(sessionKey, preMaster,
            KeyUsage.KU_UNKNOWN);
        encrypted = eData.getBytes();  // not ASN.1 encoded.

    } catch (KrbException e) {
        throw (SSLKeyException)new SSLKeyException
            ("Kerberos premaster secret error").initCause(e);
    }
}
 
Example #19
Source Project: dragonwell8_jdk   Author: alibaba   File: KrbApRep.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a KrbApRep object.
 * @param msg a byte array of reply message.
 * @param tgs_creds client's credential.
 * @exception KrbException
 * @exception IOException
 */
private KrbApRep(DerValue encoding, Credentials tgs_creds)
    throws KrbException, IOException {
    APRep rep = null;
    try {
        rep = new APRep(encoding);
    } catch (Asn1Exception e) {
        rep = null;
        KRBError err = new KRBError(encoding);
        String errStr = err.getErrorString();
        String eText;
        if (errStr.charAt(errStr.length() - 1) == 0)
            eText = errStr.substring(0, errStr.length() - 1);
        else
            eText = errStr;
        KrbException ke = new KrbException(err.getErrorCode(), eText);
        ke.initCause(e);
        throw ke;
    }

    byte[] temp = rep.encPart.decrypt(tgs_creds.key,
        KeyUsage.KU_ENC_AP_REP_PART);
    byte[] enc_ap_rep_part = rep.encPart.reset(temp);

    encoding = new DerValue(enc_ap_rep_part);
    encPart = new EncAPRepPart(encoding);
}
 
Example #20
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ArcFourCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decrypts data using specified key and initial vector.
 * @param baseKey encryption key to use
 * @param ciphertext  encrypted data to be decrypted
 * @param usage ignored
 */
public byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec,
    byte[] ciphertext, int start, int len, byte[] seqNum)
    throws GeneralSecurityException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    if (debug) {
        System.out.println("\nARCFOUR: decryptRaw with usage = " + usage);
    }

    // Derive encryption key for data
    //   Key derivation salt = 0
    byte[] klocal = new byte[baseKey.length];
    for (int i = 0; i <= 15; i++) {
        klocal[i] = (byte) (baseKey[i] ^ 0xF0);
    }
    byte[] salt = new byte[4];
    byte[] kcrypt = getHmac(klocal, salt);

    // need only first 4 bytes of sequence number
    byte[] sequenceNum = new byte[4];
    System.arraycopy(seqNum, 0, sequenceNum, 0, sequenceNum.length);

    // new encryption key salted with sequence number
    kcrypt = getHmac(kcrypt, sequenceNum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kcrypt, "ARCFOUR");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(ciphertext, start, len);

    return output;
}
 
Example #21
Source Project: jdk8u_jdk   Author: JetBrains   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decrypts data using specified key and initial vector.
 * @param baseKey encryption key to use
 * @param ciphertext  encrypted data to be decrypted
 * @param usage ignored
 */
public byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec,
    byte[] ciphertext, int start, int len)
    throws GeneralSecurityException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = decryptCTS(baseKey, usage, ivec, ciphertext,
                                    start, len, false);
    return output;
}
 
Example #22
Source Project: dragonwell8_jdk   Author: alibaba   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs encryption using derived key; adds confounder.
 */
public byte[] encrypt(byte[] baseKey, int usage,
    byte[] ivec, byte[] new_ivec, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                             + usage);
    }
    byte[] output = encryptCTS(baseKey, usage, ivec, new_ivec, plaintext,
                                    start, len, true);
    return output;
}
 
Example #23
Source Project: dragonwell8_jdk   Author: alibaba   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param baseKey key from which keys are to be derived using usage
 * @param ciphertext  E(Ke, conf | plaintext | padding, ivec) | H1[1..h]
 */
public byte[] decrypt(byte[] baseKey, int usage, byte[] ivec,
    byte[] ciphertext, int start, int len) throws GeneralSecurityException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = decryptCTS(baseKey, usage, ivec, ciphertext,
                                    start, len, true);
    return output;
}
 
Example #24
Source Project: dragonwell8_jdk   Author: alibaba   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decrypts data using specified key and initial vector.
 * @param baseKey encryption key to use
 * @param ciphertext  encrypted data to be decrypted
 * @param usage ignored
 */
public byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec,
    byte[] ciphertext, int start, int len)
    throws GeneralSecurityException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = decryptCTS(baseKey, usage, ivec, ciphertext,
                                    start, len, false);
    return output;
}
 
Example #25
Source Project: dragonwell8_jdk   Author: alibaba   File: ArcFourCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs encryption using derived key; does not add confounder.
 */
public byte[] encryptRaw(byte[] baseKey, int usage,
    byte[] seqNum, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }

    if (debug) {
        System.out.println("\nARCFOUR: encryptRaw with usage = " + usage);
    }

    // Derive encryption key for data
    //   Key derivation salt = 0
    byte[] klocal = new byte[baseKey.length];
    for (int i = 0; i <= 15; i++) {
        klocal[i] = (byte) (baseKey[i] ^ 0xF0);
    }
    byte[] salt = new byte[4];
    byte[] kcrypt = getHmac(klocal, salt);

    // Note: When using this RC4 based encryption type, the sequence number
    // is always sent in big-endian rather than little-endian order.

    // new encryption key salted with sequence number
    kcrypt = getHmac(kcrypt, seqNum);

    Cipher cipher = Cipher.getInstance("ARCFOUR");
    SecretKeySpec secretKey = new SecretKeySpec(kcrypt, "ARCFOUR");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] output = cipher.doFinal(plaintext, start, len);

    return output;
}
 
Example #26
Source Project: openjdk-8   Author: bpupadhyaya   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs encryption using derived key; does not add confounder.
 */
public byte[] encryptRaw(byte[] baseKey, int usage,
    byte[] ivec, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = encryptCTS(baseKey, usage, ivec, null, plaintext,
                                    start, len, false);
    return output;
}
 
Example #27
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decrypts data using specified key and initial vector.
 * @param baseKey encryption key to use
 * @param ciphertext  encrypted data to be decrypted
 * @param usage ignored
 */
public byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec,
    byte[] ciphertext, int start, int len)
    throws GeneralSecurityException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = decryptCTS(baseKey, usage, ivec, ciphertext,
                                    start, len, false);
    return output;
}
 
Example #28
Source Project: TencentKona-8   Author: Tencent   File: KrbCred.java    License: GNU General Public License v2.0 5 votes vote down vote up
KRBCred createMessage(Credentials delegatedCreds, EncryptionKey key)
    throws KrbException, IOException {

    EncryptionKey sessionKey
        = delegatedCreds.getSessionKey();
    PrincipalName princ = delegatedCreds.getClient();
    PrincipalName tgService = delegatedCreds.getServer();

    KrbCredInfo credInfo = new KrbCredInfo(sessionKey,
                                           princ, delegatedCreds.flags, delegatedCreds.authTime,
                                           delegatedCreds.startTime, delegatedCreds.endTime,
                                           delegatedCreds.renewTill, tgService,
                                           delegatedCreds.cAddr);

    timeStamp = KerberosTime.now();
    KrbCredInfo[] credInfos = {credInfo};
    EncKrbCredPart encPart =
        new EncKrbCredPart(credInfos,
                           timeStamp, null, null, null, null);

    EncryptedData encEncPart = new EncryptedData(key,
        encPart.asn1Encode(), KeyUsage.KU_ENC_KRB_CRED_PART);

    Ticket[] tickets = {delegatedCreds.ticket};

    credMessg = new KRBCred(tickets, encEncPart);

    return credMessg;
}
 
Example #29
Source Project: TencentKona-8   Author: Tencent   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs encryption using derived key; adds confounder.
 */
public byte[] encrypt(byte[] baseKey, int usage,
    byte[] ivec, byte[] new_ivec, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                             + usage);
    }
    byte[] output = encryptCTS(baseKey, usage, ivec, new_ivec, plaintext,
                                    start, len, true);
    return output;
}
 
Example #30
Source Project: TencentKona-8   Author: Tencent   File: AesDkCrypto.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs encryption using derived key; does not add confounder.
 */
public byte[] encryptRaw(byte[] baseKey, int usage,
    byte[] ivec, byte[] plaintext, int start, int len)
    throws GeneralSecurityException, KrbCryptoException {

    if (!KeyUsage.isValid(usage)) {
        throw new GeneralSecurityException("Invalid key usage number: "
                                            + usage);
    }
    byte[] output = encryptCTS(baseKey, usage, ivec, null, plaintext,
                                    start, len, false);
    return output;
}