Java Code Examples for javax.crypto.spec.DESKeySpec#getKey()

The following examples show how to use javax.crypto.spec.DESKeySpec#getKey() . 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 File: Vault.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private byte[] secretKeyToBytes(final SecretKey key) {
  try {
    final DESKeySpec ks = (DESKeySpec) secretKeyFactory.getKeySpec(key, DESKeySpec.class);
    return ks.getKey();
  } catch (final GeneralSecurityException e) {
    throw new IllegalStateException(e.getMessage());
  }
}
 
Example 2
Source File: DES.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected SecretKey engineGenerateSecret(
    KeySpec keySpec)
throws InvalidKeySpecException
{
    if (keySpec instanceof DESKeySpec)
    {
        DESKeySpec desKeySpec = (DESKeySpec)keySpec;
        return new SecretKeySpec(desKeySpec.getKey(), "DES");
    }

    return super.engineGenerateSecret(keySpec);
}
 
Example 3
Source File: EncryptionService.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * 
 * This method generates keys. This method is implementation specific and should not be present in any general purpose interface
 * extracted from this class.
 * 
 * @return
 * @throws Exception
 */
public static String generateEncodedKey() throws Exception {
    KeyGenerator keygen = KeyGenerator.getInstance("DES");
    SecretKey desKey = keygen.generateKey();

    // Create the cipher
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init((Cipher.WRAP_MODE), desKey);

    SecretKeyFactory desFactory = SecretKeyFactory.getInstance("DES");
    DESKeySpec desSpec = (DESKeySpec) desFactory.getKeySpec(desKey, javax.crypto.spec.DESKeySpec.class);
    byte[] rawDesKey = desSpec.getKey();

    return new String(Base64.encodeBase64(rawDesKey));
}
 
Example 4
Source File: DemonstrationGradeEncryptionServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * 
 * This method generates keys. This method is implementation specific and should not be present in any general purpose interface
 * extracted from this class.
 * 
 * @return
 * @throws Exception
 */
public static String generateEncodedKey() throws Exception {
    KeyGenerator keygen = KeyGenerator.getInstance("DES");
    SecretKey desKey = keygen.generateKey();

    // Create the cipher
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init((Cipher.WRAP_MODE), desKey);
    
    SecretKeyFactory desFactory = SecretKeyFactory.getInstance("DES");
    DESKeySpec desSpec = (DESKeySpec) desFactory.getKeySpec(desKey, javax.crypto.spec.DESKeySpec.class);
    byte[] rawDesKey = desSpec.getKey();

    return new String(Base64.encodeBase64(rawDesKey));
}
 
Example 5
Source File: DES.java    From ripple-lib-java with ISC License 5 votes vote down vote up
protected SecretKey engineGenerateSecret(
    KeySpec keySpec)
throws InvalidKeySpecException
{
    if (keySpec instanceof DESKeySpec)
    {
        DESKeySpec desKeySpec = (DESKeySpec)keySpec;
        return new SecretKeySpec(desKeySpec.getKey(), "DES");
    }

    return super.engineGenerateSecret(keySpec);
}