Package java.security.spec

Examples of java.security.spec.KeySpec


    
       throws CryptoManagerException
     {
       BigInteger D = new BigInteger(input);
      
       KeySpec keyspec = new ECPrivateKeySpec(D,(ECParameterSpec)ECCparam);
      
       PrivateKey privkey = null;
      
       try{
         privkey = KeyFactory.getInstance("ECDSA","BC").generatePrivate(keyspec);
View Full Code Here


    
       throws CryptoManagerException
     {
       ECPoint W = ECCparam.getCurve().decodePoint(input);
      
       KeySpec keyspec = new ECPublicKeySpec(W,(ECParameterSpec)ECCparam);

       try{
        
         return KeyFactory.getInstance("ECDSA", "BC").generatePublic(keyspec);
        
View Full Code Here

  /**
   * Encrypts griven string with given pass-phrase with DES.
   */
  public static String cipher(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.ENCRYPT_MODE, key);
      return toHexString(cipher.doFinal(msg.getBytes()));
View Full Code Here

  /**
   * 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

                }

                keyblob = bar.readBinaryString();

                Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
                KeySpec keyspec = new DESedeKeySpec(keydata);
                Key key = SecretKeyFactory.getInstance("DESede").generateSecret(keyspec);
                cipher.init(Cipher.DECRYPT_MODE, key,
                    new IvParameterSpec(iv, 0, cipher.getBlockSize()));

                ByteArrayReader data = new ByteArrayReader(cipher.doFinal(
View Full Code Here

                    byte[] iv = new byte[8];
                    Utils.getRND().nextBytes(iv);

                    Cipher cipher = Cipher.getInstance(
                            "DESede/CBC/PKCS5Padding");
                    KeySpec keyspec = new DESedeKeySpec(keydata);
                    Key key = SecretKeyFactory.getInstance("DESede")
                                              .generateSecret(keyspec);
                    cipher.init(Cipher.ENCRYPT_MODE, key,
                        new IvParameterSpec(iv, 0, cipher.getBlockSize()));
View Full Code Here

   */
  protected static byte[] getSharedSecret(byte[] otherPublicKeyBytes, KeyAgreement agreement) {
    BigInteger otherPublicKeyInt = new BigInteger(1, otherPublicKeyBytes);
    try {
      KeyFactory keyFactory = KeyFactory.getInstance("DH");
      KeySpec otherPublicKeySpec = new DHPublicKeySpec(otherPublicKeyInt, RTMPHandshake.DH_MODULUS, RTMPHandshake.DH_BASE);
      PublicKey otherPublicKey = keyFactory.generatePublic(otherPublicKeySpec);
      agreement.doPhase(otherPublicKey, true);
    } catch (Exception e) {
      JFLog.log("Exception getting the shared secret", e);
    }
View Full Code Here

    }   
   
    private static PublicKey getPublicKey(String algo)
            throws InvalidKeySpecException, NoSuchAlgorithmException {
        KeyFactory kf = KeyFactory.getInstance(algo);
        KeySpec kspec = null;
        if (algo.equalsIgnoreCase("DSA")) {
            kspec = new DSAPublicKeySpec(new BigInteger(DSA_Y),
                        new BigInteger(DSA_P),
                        new BigInteger(DSA_Q),
                        new BigInteger(DSA_G));
View Full Code Here

     */
    private Key getCiperKey(byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException {
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        // hashing the password 65K times takes 151ms, hashing 256 times takes 2ms.
        // Since the salt has 2^^72 values, 256 times is probably good enough.
        KeySpec spec = new PBEKeySpec(sharedKey.toCharArray(), salt, 256, 128);
        SecretKey tmp = factory.generateSecret(spec);
        SecretKey key = new SecretKeySpec(tmp.getEncoded(), "AES");
        return key;
    }
View Full Code Here

     * @return the generated key.
     */
    private SecretKey generateAESKey(String privateKey, String salt) {
        try {
            byte[] raw = Hex.decodeHex(salt.toCharArray());
            KeySpec spec = new PBEKeySpec(privateKey.toCharArray(), raw, iterationCount, keySize);
            SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF_2_WITH_HMAC_SHA_1);
            return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), AES_ECB_ALGORITHM);
        } catch (DecoderException e) {
            throw new IllegalStateException(e);
        } catch ( NoSuchAlgorithmException e) {
View Full Code Here

TOP

Related Classes of java.security.spec.KeySpec

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.