Get hex String of content String encrypted.
771187
public static String encrypt(String key, String content)
    {
        try
        {
            return ByteUtilities.encode(createAesEncryptionCipher(key).doFinal(content.getBytes(StandardCharsets.UTF_8)));
        }
        catch (Exception e)
        {
            throw new IllegalStateException("Error occurred encrypting data", e);
        }
    }
628142
def _get_random_string(length=44,
                       allowed_chars='abcdefghijklmnopqrstuvwxyz'
                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
                       secret_key=settings.secret_key_bytes()):
    
    secret_key = _ensure_bytes(secret_key)
    _reseed_if_needed(using_sysrandom, secret_key)
    return ''.join(random.choice(allowed_chars) for i in range(length))
453706
function getPubkeyHex(privkey_hex) {
   let privkey = BigInteger.fromBuffer( decodePrivateKey(privkey_hex) );
   let public_key = new bitcoinjs.ECPair(privkey);

   public_key.compressed = false;
   let public_key_str = public_key.getPublicKeyBuffer().toString('hex');
   return public_key_str;
}
1200372
public static String encryptToBase64(String content) {
        byte[] val = content.getBytes(CHARSET);
        return DatatypeConverter.printBase64Binary(val);
    }
289949
def get_bytes(self):
        """"""

        pq_io = BytesIO()
        serialize_string(pq_io, self.p)
        serialize_string(pq_io, self.q)

        ret = struct.pack("<I16s16s16sq", req_DH_params.constructor, self.nonce, self.server_nonce,
                          pq_io.getvalue(), self.public_key_fingerprint)

        bytes_io = BytesIO()
        bytes_io.write(ret)

        serialize_string(bytes_io, self.encrypted_data)

        return bytes_io.getvalue()
1223334
def hex_decode(encoded)
      encoded.scan(/[[:xdigit:]]{2}/).map { |h| h.hex.chr }.join
    end
915466
def smart_content_encoding(self):
        """"""
        encoding = self.content_encoding
        if not encoding:
            base_list = self.basename.split('.')
            while (not encoding) and len(base_list) > 1:
                _, encoding = mimetypes.guess_type('.'.join(base_list))
                base_list.pop()

        return encoding
920729
def to_hex_string(data):
    '''  '''
    if isinstance(data, int):
        return '%02X' % data
    return ':'.join([('%02X' % o) for o in data])
196234
def decrypt_ascii(self, ascii_string, key=None, digest="hex"):
        
        digests = {"hex": binascii.a2b_hex,
                   "base64": binascii.a2b_base64,
                   "hqx": binascii.a2b_hqx}
        digestor = digests.get(digest)
        if not digestor:
            TripleSecError(u"Digestor not supported.")

        binary_string = digestor(ascii_string)
        result = self.decrypt(binary_string, key)
        return result
1010266
def calculate_hex(hex_string):
        """"""
        hex_conv = hex_string.split(':')
        converted_hex = (int(hex_conv[0], 16) + int(hex_conv[1], 16))/8192

        return converted_hex
30746
def GetString(self, text, idx):
        '''
        '''
        next = string.find(text, '\x00', idx)
        chunk = text[idx:next]
        return chunk
341096
def tokhex(length=10, urlsafe=False):
    
    if urlsafe is True:
        return secrets.token_urlsafe(length)
    return secrets.token_hex(length)
1029239
private static String toHexString(byte[] bytes) {
        if (bytes.length == 0) {
            return "(empty)";
        }

        StringBuilder sb = new StringBuilder(bytes.length * 3 - 1);
        boolean isInitial = true;
        for (byte b : bytes) {
            if (isInitial) {
                isInitial = false;
            } else {
                sb.append(':');
            }

            int k = b & 0xFF;
            sb.append(HEXES[k >>> 4]);
            sb.append(HEXES[k & 0xF]);
        }

        return sb.toString();
    }
1249225
def _cbc_decrypt(self, final_key, crypted_content):
        """"""

        # Just decrypt the content with the created key
        aes = AES.new(final_key, AES.MODE_CBC, self._enc_iv)
        decrypted_content = aes.decrypt(crypted_content)
        padding = decrypted_content[-1]
        if sys.version > '3':
            padding = decrypted_content[-1]
        else:
            padding = ord(decrypted_content[-1])
        decrypted_content = decrypted_content[:len(decrypted_content)-padding]
        
        return decrypted_content
490242
def decode_from_sha(sha):
    """"""
    if isinstance(sha, str):
        sha = sha.encode('utf-8')
    return codecs.decode(re.sub(rb'(00)*$', b'', sha), "hex_codec")
190034
def str2bytes(x):
  """"""
  if type(x) is bytes:
    return x
  elif type(x) is str:
    return bytes([ ord(i) for i in x ])
  else:
    return str2bytes(str(x))
634958
public static String decrypt(Key key, String content) throws Exception {
        try {
            Cipher cipher = Cipher.getInstance(CRYPTO_ALGORITHM);
            cipher.init(Cipher.DECRYPT_MODE, key);
            return new String(cipher.doFinal(Base64.decodeBase64(content)));
        } catch (Exception e) {
            log.error("Error while decrypting", e);
            throw e;
            
        }
    }