Package javax.crypto.spec

Examples of javax.crypto.spec.DESKeySpec


  /**
   * Decrypts griven string with given pass-phrase with DES.
   */
  public static String decipher(String msg, byte[] passPhrase) {
    try {
      KeySpec keySpec = new DESKeySpec(passPhrase);
      SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(
          keySpec);
      Cipher cipher = Cipher.getInstance(key.getAlgorithm());
      cipher.init(Cipher.DECRYPT_MODE, key);
      return new String(cipher.doFinal(fromHexString(msg)));
View Full Code Here


          deskey[i] = key[i];
        } else {
          deskey[i] = 0;
        }
      }
      key = (new DESKeySpec(deskey)).getKey();

    } else if (algorithm.equals("DESede")) {
      byte[] desedekey = new byte[24];
      for (int i=0; i<24; i++) {
        if (i < key_length) {
View Full Code Here

  }

  private static Key getKey() {
    try {
      byte[] bytes = getBytes(KEY_STRING);
      DESKeySpec pass = new DESKeySpec(bytes);
      SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); //$NON-NLS-1$
      SecretKey s = skf.generateSecret(pass);
      return s;
    } catch (Exception e) {
            Debug.error(e.toString());
View Full Code Here

            {
                byte[]  bytes = key.getEncoded();

                try
                {
                    return new DESKeySpec(bytes);
                }
                catch (Exception e)
                {
                    throw new InvalidKeySpecException(e.toString());
                }
View Full Code Here

            KeySpec keySpec)
        throws InvalidKeySpecException
        {
            if (keySpec instanceof DESKeySpec)
            {
                DESKeySpec desKeySpec = (DESKeySpec)keySpec;
                return new SecretKeySpec(desKeySpec.getKey(), "DES");
            }

            return super.engineGenerateSecret(keySpec);
        }
View Full Code Here

        String sKeyText = gCipherKey != null ? gCipherKey : generateKey(gCipherSeed);
        byte[] baKeyBytes = textToBytes(sKeyText);

        try {
            SecretKeyFactory desFactory = SecretKeyFactory.getInstance("DES");
            gKey = desFactory.generateSecret(new DESKeySpec(baKeyBytes));
        } catch (InvalidKeyException e) {
            throw e;
        } catch (InvalidKeySpecException e) {
            throw e;
        }
View Full Code Here

     */
    public void setPassword(String p) throws FacesException {
        byte[] s = { (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x34, (byte) 0xE3, (byte) 0x03 };

        try {
            KeySpec keySpec = new DESKeySpec(p.getBytes("UTF8"));
            SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec);

            e = Cipher.getInstance(key.getAlgorithm());
            d = Cipher.getInstance(key.getAlgorithm());

View Full Code Here

            KeySpec keySpec)
        throws InvalidKeySpecException
        {
            if (keySpec instanceof DESKeySpec)
            {
                DESKeySpec desKeySpec = (DESKeySpec)keySpec;
                return new SecretKeySpec(desKeySpec.getKey(), "DES");
            }

            return super.engineGenerateSecret(keySpec);
        }
View Full Code Here

        if (!DEFSupported) {
            fail(NotSupportMsg);
            return;
        }
        byte[] bb = new byte[24];
        KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec)new DESKeySpec(bb) :
            (KeySpec)new DESedeKeySpec(bb));
        KeySpec rks = null;
        SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm);
        SecretKey secKey = null;
        SecretKeyFactory[] skF = createSKFac();
View Full Code Here

  public void before() throws Exception
  {
    File file = File.createTempFile("ha-jdbc", "keystore");
   
    SecretKeyFactory factory = SecretKeyFactory.getInstance(ALGORITHM);
    this.key = factory.generateSecret(new DESKeySpec(Base64.decodeBase64(KEY.getBytes())));
    KeyStore store = KeyStore.getInstance(CipherCodecFactory.Property.KEYSTORE_TYPE.defaultValue);
    store.load(null, null);
    store.setKeyEntry(CipherCodecFactory.Property.KEY_ALIAS.defaultValue, this.key, KEY_PASSWORD.toCharArray(), null);
   
    FileOutputStream out = new FileOutputStream(file);
View Full Code Here

TOP

Related Classes of javax.crypto.spec.DESKeySpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.