Beispiel #1
0
def decryptJython(payload, key, iv):
    decoded = Base64.getDecoder().decode(payload)
    aesKey = SecretKeySpec(key, "AES")
    aesIV = IvParameterSpec(iv)
    cipher = Cipher.getInstance("AES/CFB/NOPADDING")
    cipher.init(Cipher.DECRYPT_MODE, aesKey, aesIV)
    return cipher.doFinal(decoded)
    def encrypto(self, payload, key, iv):
		aesKey = SecretKeySpec(base64.b64decode(key), "AES")
		aesIV = IvParameterSpec(base64.b64decode(iv))
		cipher = Cipher.getInstance("AES/CBC/PKCS7Padding")
		cipher.init(Cipher.ENCRYPT_MODE, aesKey, aesIV)
		encrypted = cipher.doFinal(payload)
		return Base64.getEncoder().encode(encrypted)
Beispiel #3
0
def encryptJython(payload, key, iv):
    aesKey = SecretKeySpec(key, "AES")
    aesIV = IvParameterSpec(iv)
    cipher = Cipher.getInstance("AES/CFB/NOPADDING")
    cipher.init(Cipher.ENCRYPT_MODE, aesKey, aesIV)
    encrypted = cipher.doFinal(payload)
    return Base64.getEncoder().encode(encrypted)
 def AESCipherdecrypt(self, key, enc):
     enc, iv = enc.split(':')
     cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
     cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(key.decode("hex"),
                                                    "AES"),
                 IvParameterSpec(iv.decode("hex")))
     decrypted_password = cipher.doFinal(enc.decode("hex"))
     return decrypted_password.tostring()
Beispiel #5
0
 def __init__(self, alg, mode, key, iv=None):
     modestr = _modes.get(mode, "/ECB/NoPadding")
     keyspec = SecretKeySpec(key, alg)
     self.__keysize = len(key)
     self.IV = iv
     if iv is None or mode == blockalgo.MODE_ECB:
         if mode != blockalgo.MODE_ECB:
             raise ValueError('mode requires an IV')
         self.__cryptor = JCECipher.getInstance(alg + modestr)
         self.__cryptor.init(JCECipher.ENCRYPT_MODE, keyspec)
         self.__decryptor = JCECipher.getInstance(alg + modestr)
         self.__decryptor.init(JCECipher.DECRYPT_MODE, keyspec)
     else:
         ivspec = IvParameterSpec(iv)
         self.__cryptor = JCECipher.getInstance(alg + modestr)
         self.__cryptor.init(JCECipher.ENCRYPT_MODE, keyspec, ivspec)
         self.__decryptor = JCECipher.getInstance(alg + modestr)
         self.__decryptor.init(JCECipher.DECRYPT_MODE, keyspec, ivspec)
    def decrypto(self, payload, key, iv):
		decoded = base64.b64decode(payload)
		
		aesKey = SecretKeySpec(base64.b64decode(key), "AES")
		
		aesIV = IvParameterSpec(base64.b64decode(iv))
		
		cipher = Cipher.getInstance("AES/CBC/PKCS7Padding","BC")
		cipher.init(Cipher.DECRYPT_MODE, aesKey, aesIV)
		return String(cipher.doFinal(decoded)) 
Beispiel #7
0
	def encrypt(self, pystrPlaintext):
		try:
			plaintext = JavaString(pystrPlaintext)
			keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES")
			key = keyFactory.generateSecret(PBEKeySpec(self.PASSWORD))
			pbeCipher = Cipher.getInstance("PBEWithMD5AndDES")
			paramSpec = PBEParameterSpec(self.SALT, 20)
			pbeCipher.init(Cipher.ENCRYPT_MODE, key, paramSpec)
			return self._base64Encode(pbeCipher.doFinal(plaintext.getBytes()))
		except:
			raise
Beispiel #8
0
	def decrypt(self, pystrProperty):
		try:
			strProperty = JavaString(pystrProperty)
			keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES")
			key = keyFactory.generateSecret(PBEKeySpec(self.PASSWORD))
			pbeCipher = Cipher.getInstance("PBEWithMD5AndDES")
			paramSpec = PBEParameterSpec(self.SALT, 20)
			pbeCipher.init(Cipher.DECRYPT_MODE, key, paramSpec)
			return pbeCipher.doFinal(self._base64Decode(strProperty)).tostring()
		except:
			raise
def encrypt(payload, key):
    salt = bytearray([1,2,3,4,5,6,7,8])
    k2, iv2 = derive_key_and_iv(key, salt, 32, 16)
    aesKey = SecretKeySpec(k2, "AES")
    aesIV = IvParameterSpec(iv2)
    # print key, binascii.hexlify(salt), binascii.hexlify(k2), binascii.hexlify(iv2), payload, "TESTING - ENCRYPT"

    cipher = Cipher.getInstance("AES/CBC/PKCS7Padding")
    cipher.init(Cipher.ENCRYPT_MODE, aesKey, aesIV)
    encrypted = cipher.doFinal(payload)
    out = Base64.getEncoder().encode(b'Salted__' + salt + encrypted)
    # print("DEBUG enc:", out.tostring(), binascii.hexlify(salt), binascii.hexlify(k2), binascii.hexlify(iv2), key)
    return out
Beispiel #10
0
 def decryptAES(self, key, encryptedStr):
     # make sure key length is 16 bytes (128 bits)
     if ( len(key) != 16 ):
         return None
     # split the encrypted string into IV and ciphertext
     iv, encrypted = encryptedStr[:16], encryptedStr[16:]
     # configure IV and key specification
     skeySpec = SecretKeySpec(key, "AES")
     ivspec = IvParameterSpec(iv)
     # setup cipher
     cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
     cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec)
     # decrypt the plaintext
     encodedBytes = base64.b64decode( b'' + encrypted )
     decodedBytes = cipher.doFinal( encodedBytes )
     plaintext    = ''.join(chr(i) for i in decodedBytes)
     return plaintext
Beispiel #11
0
 def encryptAES(self, key, toEncrypt):
     # make sure key length is 16 bytes (128 bits)
     if ( len(key) != 16 ):
         return None
     # generate a random IV
     randomSource = string.ascii_letters + string.digits
     iv = ''.join(random.SystemRandom().choice(randomSource) for i in range(16))
     # configure IV and key specification
     skeySpec = SecretKeySpec(key, "AES")
     ivspec = IvParameterSpec(iv)
     # setup cipher
     cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
     cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec)
     # encrypt the plaintext
     encryptedBytes = cipher.doFinal( toEncrypt.encode('utf-8') )
     encryptedValue = base64.b64encode( encryptedBytes )
     return iv.encode("ascii") + encryptedValue
    def __init__(self, gateway_host, gateway_password, private_password):
        self.host = gateway_host

        key1 = hashlib.md5()
        key1.update(gateway_password)
        key1.update(self.SALT)

        key2 = hashlib.md5()
        key2.update(self.SALT)
        key2.update(private_password)

        self.key = key1.digest() + key2.digest()

        self.opener = urllib2.build_opener()
        self.opener.addheaders = [('User-agent', 'TeleHeater/2.2.3'), ('Accept', 'application/json')]

        self.secretKey = SecretKeySpec(self.key, "AES")
        self.cipher = Cipher.getInstance("AES/ECB/NoPadding")
def decrypt(payload, key):
    decoded = Base64.getDecoder().decode(payload)
    # print("Lol - decoded: ", decoded)

    if decoded.tostring()[:8] != "Salted__":
        print decoded.tostring()[:8]
        return False
    decoded = decoded[8:]
    
    salt = decoded[:8]
    k2, iv2 = derive_key_and_iv(key, salt, 32, 16)
    # print key, binascii.hexlify(salt), binascii.hexlify(k2), binascii.hexlify(iv2), payload, "TESTING - DECRYPT"
    aesKey = SecretKeySpec(k2, "AES")
    aesIV = IvParameterSpec(iv2)

    cipher = Cipher.getInstance("AES/CBC/PKCS7Padding")
    cipher.init(Cipher.DECRYPT_MODE, aesKey, aesIV)
    return cipher.doFinal(decoded[8:])
Beispiel #14
0
    def __init__(self, gateway_host, gateway_password, private_password):
        self.host = gateway_host

        key1 = hashlib.md5()
        key1.update(gateway_password)
        key1.update(self.SALT)

        key2 = hashlib.md5()
        key2.update(self.SALT)
        key2.update(private_password)

        self.key = key1.digest() + key2.digest()

        self.opener = urllib2.build_opener()
        self.opener.addheaders = [('User-agent', 'TeleHeater/2.2.3'),
                                  ('Accept', 'application/json')]

        self.secretKey = SecretKeySpec(self.key, "AES")
        self.cipher = Cipher.getInstance("AES/ECB/NoPadding")
Beispiel #15
0
 def decrypt(key, ciphertext):
     secretkey = SecretKeySpec(key, 'AES')
     cipher = Cipher.getInstance('AES/ECB/NoPadding')
     cipher.init(Cipher.DECRYPT_MODE, secretkey)
     decrypted = cipher.doFinal(ciphertext)
     return decrypted.tostring()
Beispiel #16
0
from java.math import BigInteger
from java.security import *
from javax.crypto import KeyGenerator, SecretKey, Cipher
from javax.crypto.spec import SecretKeySpec

from org.apache.log4j import Logger
from org.apache.commons.codec.binary import Base64

log = Logger.getLogger('password_encrypter')
kgen = KeyGenerator.getInstance("AES")
kgen.init(128)
skey = kgen.generateKey()
raw = skey.getEncoded()
rawkey = Base64.encodeBase64(raw).tostring()
skeySpec = SecretKeySpec(raw, "AES")
cipher = Cipher.getInstance("AES")


def encryptPassword(password):
    if password is not None and password is not ' ':
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec)
        encrypted = cipher.doFinal(password)
        encodeTxt = Base64.encodeBase64(encrypted)
        return encodeTxt.tostring()


def encryptAllPasswords(configfile):
    log.info("Encrypting Passwords in config file")
    if (configfile is not None and not ''):
        if not configfile.endswith('.properties'):
            configfile = configfile + '.properties'
Beispiel #17
0
def aesEncrypt(data, key):
    cipher = Cipher.getInstance('AES/CTR/NoPadding')
    skeySpec = SecretKeySpec(key, 'AES')
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, _iv)
    return cipher.doFinal(data).tostring()
from java.lang import *
from java.security import Key
from javax.crypto import Cipher
from javax.crypto import KeyGenerator
from array import array
#must import for dec it is user made file
from dec_file import dec

algo = "RC2"
key = KeyGenerator.getInstance(algo).generateKey()
cipher = Cipher.getInstance(algo)


def enc(text, key, cipher):
    cipher.init(Cipher.ENCRYPT_MODE, key)
    #string = ""
    #for l in text:
    #	string +=
    return cipher.doFinal(array("b", text.encode("utf-8")))
    #return string


#def dec(byar,key,cipher):
#	cipher.init("Cipher.DECRYPT_MODE,key)
#	print (cipher.doFinal(byar))

#key = KeyGenerator.getInstance(algo).generateKey()
#cipher = Cipher.getInstance(algo)
print("plain-text - hello world")
x = enc("hello world", key, cipher)
print("cipher-text - ")
Beispiel #19
0
 def decrypt(key, ciphertext):
     secretkey = SecretKeySpec(key, 'AES')
     cipher = Cipher.getInstance('AES/ECB/NoPadding')
     cipher.init(Cipher.DECRYPT_MODE, secretkey)
     decrypted = cipher.doFinal(ciphertext)
     return decrypted.tostring()
Beispiel #20
0
def getKeyLength():
    maxlen = Cipher.getMaxAllowedKeyLength('AES/CTR/NoPadding')
    return min(maxlen, 256) / 8