Examples of SecretKeySpec


Examples of javax.crypto.spec.SecretKeySpec

    public SignedRequestsHelper(String awsAccessKeyId, String awsSecretKey) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
        this.awsAccessKeyId = awsAccessKeyId;
        this.awsSecretKey = awsSecretKey;

        byte[] secretyKeyBytes = this.awsSecretKey.getBytes(UTF8_CHARSET);
        this.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
        this.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
        this.mac.init(secretKeySpec);
    }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   * @throws IOException if an error occurs
   */
  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

        }
    }

    protected static SecretKey createMacKey(String algorithm, byte[] macKey)
    {
        return new SecretKeySpec(macKey, algorithm);
    }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

        SecretKey secretKey = Association.generateMacSha1Key();

        assertNotNull(secretKey);
        assertTrue(secretKey instanceof SecretKeySpec);

        SecretKeySpec secretKeySpec = (SecretKeySpec) secretKey;

        assertEquals(Association.HMAC_SHA1_ALGORITHM.toUpperCase(), secretKeySpec.getAlgorithm().toUpperCase());
        assertEquals(20, secretKeySpec.getEncoded().length);
    }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            SecretKey secretKey = Association.generateMacSha256Key();

            assertNotNull(secretKey);
            assertTrue(secretKey instanceof SecretKeySpec);

            SecretKeySpec secretKeySpec = (SecretKeySpec) secretKey;

            assertEquals(Association.HMAC_SHA256_ALGORITHM.toUpperCase(), secretKeySpec.getAlgorithm().toUpperCase());
            assertEquals(32, secretKeySpec.getEncoded().length);
        }
    }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

    * @return the secret key for the SignedInfo element.
    */
   public SecretKey createSecretKey(byte[] secretKeyBytes)
   {

      return new SecretKeySpec(secretKeyBytes,
                               this._signatureAlgorithm
                                  .getJCEAlgorithmString());
   }
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

                j ^= j >> 1;
                j = (j & 1) ^ 1;
                inKey[i] = (byte) ((k | j) & 0xFF);
            }

            SecretKeySpec secretKey = new SecretKeySpec(inKey, "DES");

            decrypter = Cipher.getInstance("DES/CBC/NoPadding");
            encrypter = Cipher.getInstance("DES/CBC/NoPadding");

            // IV is all 0s for RTP DES
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

    public AESCrypt(String password) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Key = md5.digest(password.getBytes("UTF-8"));

            SecretKeySpec secretKey = new SecretKeySpec(md5Key, "AES");

            decrypter = Cipher.getInstance("AES/ECB/NoPadding");
            encrypter = Cipher.getInstance("AES/ECB/NoPadding");

            decrypter.init(Cipher.DECRYPT_MODE, secretKey);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

     *  resolution of the key fails for any reason
     */
    protected Object readResolve() throws ObjectStreamException {
  try {
      if (type == Type.SECRET && RAW.equals(format)) {
    return new SecretKeySpec(encoded, algorithm);
      } else if (type == Type.PUBLIC && X509.equals(format)) {
    KeyFactory f = KeyFactory.getInstance(algorithm);
    return f.generatePublic(new X509EncodedKeySpec(encoded));
      } else if (type == Type.PRIVATE && PKCS8.equals(format)) {
    KeyFactory f = KeyFactory.getInstance(algorithm);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   
    private static String decode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
            InvalidKeyException, BadPaddingException, IllegalBlockSizeException
    {
      byte[] kbytes = "jaas is the way".getBytes();
      SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
 
      BigInteger n = new BigInteger(secret, 16);
      byte[] encoding = n.toByteArray();
     
      Cipher cipher = Cipher.getInstance("Blowfish");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.