コード例 #1
0
ファイル: DESPlus.java プロジェクト: hebut/jxkh
 /**
  * 加密字节数组
  *
  * @param arrB 需加密的字节数组
  * @return 加密后的字节数组
  * @throws Exception
  */
 public byte[] encrypt(byte[] arrB) {
   try {
     return encryptCipher.doFinal(arrB);
   } catch (IllegalBlockSizeException e) {
     e.printStackTrace();
   } catch (BadPaddingException e) {
     e.printStackTrace();
   }
   return arrB;
 }
コード例 #2
0
 private static byte[] func_75885_a(int p_75885_0_, Key p_75885_1_, byte p_75885_2_[]) {
   try {
     return func_75886_a(p_75885_0_, p_75885_1_.getAlgorithm(), p_75885_1_).doFinal(p_75885_2_);
   } catch (IllegalBlockSizeException illegalblocksizeexception) {
     illegalblocksizeexception.printStackTrace();
   } catch (BadPaddingException badpaddingexception) {
     badpaddingexception.printStackTrace();
   }
   System.err.println("Cipher data failed!");
   return null;
 }
コード例 #3
0
 public static byte[] encryptData(Key key, byte[] toEncrypt) {
   try {
     Cipher cipher = Cipher.getInstance(key.getAlgorithm());
     cipher.init(Cipher.ENCRYPT_MODE, key);
     return cipher.doFinal(toEncrypt);
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (NoSuchPaddingException e) {
     e.printStackTrace();
   } catch (InvalidKeyException e) {
     e.printStackTrace();
   } catch (BadPaddingException e) {
     e.printStackTrace();
   } catch (IllegalBlockSizeException e) {
     e.printStackTrace();
   }
   return new byte[0];
 }
コード例 #4
0
  public Object transformMessage(MuleMessage message, String outputEncoding)
      throws TransformerException {

    Arrays.fill(ivBytes, (byte) 0x00);
    iv = new IvParameterSpec(ivBytes);

    Object derivedKey = message.getInvocationProperty("derivedKey");
    if (null == derivedKey) {
      keyValue = Base64.decodeBase64(DEFAULT_KEY.getBytes());
    } else {
      keyValue = Base64.decodeBase64(derivedKey.toString().getBytes());
    }
    SecretKeySpec skeySpec = new SecretKeySpec(keyValue, "AES");

    Cipher cipher = null;
    try {
      cipher = Cipher.getInstance(ALGO);
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    } catch (NoSuchPaddingException e1) {
      e1.printStackTrace();
    }

    try {
      cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
    } catch (InvalidKeyException | InvalidAlgorithmParameterException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    byte[] original = null;
    try {
      // Object queryParm1 = message.getPayload().toString());	//"2zU3YSkvbamjrlE7WgBaKA==");
      // Object queryParm1 = message.getInvocationProperty("1");

      // HashMap queryParms = (HashMap)message.getInboundProperty("http.query.params");
      // Object queryParm1 = queryParms.get("1");

      Object queryParm1 = message.getInvocationProperty("encryptedPatientId");

      if (queryParm1 != null) {
        byte[] encString = Base64.decodeBase64(queryParm1.toString().getBytes());
        original = cipher.doFinal(encString);

        String clearText = "";
        try {
          clearText = new String(original, UNICODE_FORMAT).trim();
          // message.setInvocationProperty("patientId", clearText);
          message.setOutboundProperty("patientId", clearText);

        } catch (UnsupportedEncodingException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
      }

    } catch (IllegalBlockSizeException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (BadPaddingException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    return message;
  }