<p>Encrypts and Base64 encodes a message.</p>
@param message the message
@return the encrypted message
@throws GeneralSecurityException
480515
public String encrypt(String message) throws GeneralSecurityException {
		byte[] bytes = encryptor.encrypt(message.getBytes());
		return Base64.getEncoder().encodeToString(bytes);
	}
1349789
public static byte[] AesDecryptByBase64Str(String base64String,byte[] decryptKey) throws Exception {
		byte[] content=Base64Decode(base64String);
		return AesDecryptByBytes(content, decryptKey);
	}
251552
@Override
  public <T> T decode(Message message, java.lang.Class<T> yourDomainMessageObject) throws RecoderException {
    Object rc = null;
    ClassInfo c = storage.getClassInfo(yourDomainMessageObject);
    CommandDscr cd = c.getAnnotation(CommandDscr.class);
    if (cd != null) {
      try {
        if (message.getCommandCode() != cd.code()) {
          throw new IllegalArgumentException("Invalid message code " + message.getCommandCode());
        }
        if (message.getApplicationId() != 0 && message.getApplicationId() != cd.appId()) {
          throw new IllegalArgumentException("Invalid Application-Id " + message.getApplicationId());
        }
        for (CommandFlag f : cd.flags()) {
          switch (f) {
            case E:
              if (!message.isError()) {
                throw new IllegalArgumentException("Flag e is not set");
              }
              break;
            case P:
              if (!message.isProxiable()) {
                throw new IllegalArgumentException("Flag p is not set");
              }
              break;
            case R:
              if (!message.isRequest()) {
                throw new IllegalArgumentException("Flag m is not set");
              }
              break;
            case T:
              if (!message.isReTransmitted()) {
                throw new IllegalArgumentException("Flag t is not set");
              }
              break;
          }
        }
        // Find max constructor + lost avp set by setters
        int cacount = 0;
        Constructor<?> cm = null;
        Map<String, Class<?>> cmargs = new HashMap<String, Class<?>>();
        for (ConstructorInfo ci : c.getConstructorsInfo()) {
          if (ci.getAnnotation(Setter.class) != null) {
            // check params - all params must have avp annotation
            Class<?>[] params = ci.getConstructor().getParameterTypes();
            boolean correct = true;
            for (Class<?> j : params) {
              if (j.isArray()) {
                j = j.getComponentType();
              }
              if (storage.getClassInfo(j).getAnnotation(AvpDscr.class) == null) {
                correct = false;
                break;
              }
            }
            if (!correct) {
              continue;
            }
            // find max args constructor
            if (cacount < params.length) {
              cacount = params.length;
              cm = ci.getConstructor();
            }
          }
        }
        // fill cm args
        List<Object> initargs = new ArrayList<Object>();
        if (cm != null) {
          for (Class<?> ac : cm.getParameterTypes()) {
            Class<?> lac = ac.isArray() ? ac.getComponentType() : ac;
            cmargs.put(lac.getName(), ac);
            // Create params
            initargs.add(createChildByAvp(findChildDscr(cd.childs(), ac), ac, message.getAvps()));
          }
          // Create instance class
          rc = cm.newInstance(initargs.toArray());
        } else {
          rc = yourDomainMessageObject.newInstance();
        }
        //
        for (MethodInfo mi : c.getMethodsInfo()) {
          if (mi.getAnnotation(Setter.class) != null) {
            Class<?>[] pt = mi.getMethod().getParameterTypes();
            if (pt.length == 1 && storage.getClassInfo(pt[0]).getAnnotation(AvpDscr.class) != null) {
              Class<?> ptc = pt[0].isArray() ? pt[0].getComponentType() : pt[0];
              if (!cmargs.containsKey(ptc.getName())) {
                cmargs.put(ptc.getName(), ptc);
                mi.getMethod().invoke(rc, createChildByAvp(findChildDscr(cd.childs(), pt[0]), pt[0], message.getAvps()));
              }
            }
          }
        }
        // Fill undefined avp
        setUndefinedAvp(message.getAvps(), rc, c, cmargs);
      } catch (InstantiationException e) {
        throw new RecoderException(e);
      } catch (InvocationTargetException e) {
        throw new RecoderException(e);
      } catch (IllegalAccessException e) {
        throw new RecoderException(e);
      }
    }
    return (T) rc;
  }
3348
public String getDecodedMessage()
    {
        if (message == null)
        {
            return null;
        }
        return new String(Base64.base64ToByteArray(message), Charset.forName("UTF-8"));
    }
116373
public static String decrypt(String encrypted) {
        try {
            return decrypt(encrypted, null);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            return null;
        }
    }
386317
def encrypt(message, key: nil)

      raise ArgumentError.new('The message argument is required.') if message.blank?
      raise ArgumentError.new('The key argument is required.')     if key.blank?

      cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
      cipher.encrypt
      cipher.padding = aes_256_padding
      cipher.key     = key

      cipher.update(message)+cipher.final

    end
30928
public byte[] decrypt(byte[] msg) {
        if (msg == null) return null;
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM_IMPLEMENTATION);
            SecretKeySpec key = new SecretKeySpec(getMd5(), ENCRYPTION_ALGORITHM);
            IvParameterSpec iv = new IvParameterSpec(getIv());
            cipher.init(Cipher.DECRYPT_MODE, key, iv);
            return cipher.doFinal(msg);
        } catch (Exception e) {
            return null;
        }
    }
1287252
private Cipher createCipher() throws GeneralSecurityException {
		if(algorithmProvider != null) {
			return Cipher.getInstance(algorithm, algorithmProvider);
		} else {
			return Cipher.getInstance(algorithm);
		}
	}
1027607
public static byte[] generateKey()
        throws GeneralSecurityException
    {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM);
        // java max 128
        keyGenerator.init(128);
        SecretKey secretKey = keyGenerator.generateKey();
        return secretKey.getEncoded();
    }
165132
public void decrypt(byte[] password) throws GeneralSecurityException {
        if (!isEncrypted()) {
            return;
        }

        byte[] enc = Base64.decode(this.encodedKey);

        SecretKeySpec key = getSecretKey(password, this.initializationVector.getIV());

        Cipher cipher = getCipher();
        cipher.init(Cipher.DECRYPT_MODE, key, this.initializationVector);
        enc = cipher.doFinal(enc);

        this.intKey = getKey(this.keyAlg, enc);
        this.keyData = enc;
        this.isEncrypted = false;
        this.encodedKey = null;
    }
1038409
public function encrypt($message)
	{
		$crypted = NULL;
		
		openssl_public_encrypt($message, $crypted, $this->publicKey);
		
		return base64_encode($crypted);
	}
649969
def encrypt(self, plaintext):
        """"""

        # String to bytes.
        plainbytes = plaintext.encode('utf8')

        # Compress plaintext bytes.
        compressed = zlib.compress(plainbytes)

        # Construct AES-GCM cipher, with 96-bit nonce.
        cipher = AES.new(self.cipher_key, AES.MODE_GCM, nonce=random_bytes(12))

        # Encrypt and digest.
        encrypted, tag = cipher.encrypt_and_digest(compressed)

        # Combine with nonce.
        combined = cipher.nonce + tag + encrypted

        # Encode as Base64.
        cipherbytes = base64.b64encode(combined)

        # Bytes to string.
        ciphertext = cipherbytes.decode('utf8')

        # Return ciphertext.
        return ciphertext
625194
def decrypt(self, message):
        

        # Unserialize the encrypted message
        message = json.loads(message)

        # Set up a list for the unencrypted lines of the message
        unencrypted_msg = []

        for line in message:

            # Convert from ascii back to bytestring
            enc_line = binascii.a2b_base64(line)

            # Decrypt the line using our private key
            unencrypted_line = rsa.decrypt(enc_line, self.private_key)

            unencrypted_msg.append(unencrypted_line)

        # Convert the message from a list back into a string
        unencrypted_msg = "".join(unencrypted_msg)

        return unencrypted_msg
273693
public byte[] crypt(final byte[] msg) {
		final ReadLock readLock = this.lock.readLock();
		readLock.lock();
		byte[] code;
		try {
			final int[] sbox = this.sbox.clone();
			code = new byte[msg.length];
			int i = 0;
			int j = 0;
			for (int n = 0; n < msg.length; n++) {
				i = (i + 1) % SBOX_LENGTH;
				j = (j + sbox[i]) % SBOX_LENGTH;
				swap(i, j, sbox);
				int rand = sbox[(sbox[i] + sbox[j]) % SBOX_LENGTH];
				code[n] = (byte) (rand ^ msg[n]);
			}
		} finally {
			readLock.unlock();
		}
		return code;
	}
210697
public static String decrypt(String keyBase64, String encrypted) {
        return decrypt(Base64.decodeBase64(keyBase64.getBytes(StandardCharsets.UTF_8)), encrypted);
    }
1125303
def group_encrypt(self, groupid, message):
        
        logger.debug("group_encrypt(groupid=%s, message=%s)" % (groupid, message))
        group_cipher = self._get_group_cipher(groupid, self._username)
        return group_cipher.encrypt(message + self._generate_random_padding())
299248
@Override
    public Cipher encrypt() {
        try {
            Cipher cipher = Cipher.getInstance(ALGORITHM);
            cipher.init(Cipher.ENCRYPT_MODE, getKey());
            return cipher;
        } catch (GeneralSecurityException e) {
            throw new AssertionError(e);
        }
    }