예제 #1
0
파일: cryptfile.py 프로젝트: wrtcoder/stuff
def execute_encryption():
    inputfilename = None
    outputfilename = None
    keyfilename = None
    decryptFlag = False
    global cipher

    optlist, args = getopt.getopt(sys.argv[1:], "i:o:k:d")
    for (option, value) in optlist:
        if option == '-i':
            inputfilename = value
        elif option == '-o':
            outputfilename = value
        elif option == '-k':
            keyfilename = value
        elif option == '-d':
            decryptFlag = True

    # check to see if we got enough parameters
    if keyfilename is None and inputfilename is None:
        sys.stderr.write("Error: must specify either keyfile or input file.\n")
        sys.exit(1)
        return

    cipher = twofish.twofish()

    # okay, if we have a keyfilename, do that, else prompt for key:
    if keyfilename is not None:
        set_key_from_file(cipher, keyfilename)
    else:
        prompt_for_key(cipher)
        pass

    if inputfilename is not None:
        inputfile = open(inputfilename, "r")
        if outputfilename is None:
            outputfilename = inputfilename + ".tfe"
    else:
        inputfile = sys.stdin

    if outputfilename:
        outputfile = open(outputfilename, "w")
    else:
        outputfile = sys.stdout

    if decryptFlag:
        cipher.decrypt_cfb_file(inputfile, outputfile)
    else:
        cipher.encrypt_cfb_file(inputfile, outputfile)
예제 #2
0
파일: cryptfile.py 프로젝트: ChrisX34/stuff
def execute_encryption():
    inputfilename = None
    outputfilename = None
    keyfilename = None
    decryptFlag = False
    global cipher

    optlist, args = getopt.getopt(sys.argv[1:], "i:o:k:d")
    for (option, value) in optlist:
        if option == '-i':
            inputfilename = value
        elif option == '-o':
            outputfilename = value
        elif option == '-k':
            keyfilename = value
        elif option == '-d':
            decryptFlag = True

    # check to see if we got enough parameters
    if keyfilename is None and inputfilename is None:
	sys.stderr.write("Error: must specify either keyfile or input file.\n")
	sys.exit(1)
	return

    cipher=twofish.twofish()

    # okay, if we have a keyfilename, do that, else prompt for key:
    if keyfilename is not None:
	set_key_from_file(cipher,keyfilename)
    else:
	prompt_for_key(cipher)
	pass

    if inputfilename is not None:
	inputfile=open(inputfilename,"r")
	if outputfilename is None:
	    outputfilename=inputfilename+".tfe"
    else:
	inputfile=sys.stdin

    if outputfilename:
	outputfile=open(outputfilename,"w")
    else:
	outputfile=sys.stdout

    if decryptFlag:
        cipher.decrypt_cfb_file(inputfile, outputfile)
    else:
        cipher.encrypt_cfb_file(inputfile, outputfile)
예제 #3
0
if len(sys.argv) > 1:
    tarballUri = sys.argv[1]
else:
    print __doc__
    sys.exit(1)

tarballName = os.path.join("/tmp", os.path.split(tarballUri)[-1])
password = raw_input("Password: "******"Can't find tarball at that location, please check spelling"
    sys.exit(1)
outputfile = open(tarballName, "w")
if password:
    cipher = twofish.twofish()
    m = hashlib.md5()
    m.update(password)
    key = m.digest()
    cipher.setkey(key)
    cipher.decrypt_cfb_file(inputfile, outputfile)
else:
    blocksize = 1024 * 1024
    s = inputfile.read(blocksize)
    while s:
        outputfile.write(s)
        s = inputfile.read(blocksize)
inputfile.close()
outputfile.close()
os.chdir("/tmp")
if os.system("tar xfz " + tarballName) != 0:
예제 #4
0
if len(sys.argv) > 1:
    tarballUri = sys.argv[1]
else:
    print __doc__
    sys.exit(1)

tarballName = os.path.join("/tmp", os.path.split(tarballUri)[-1])
password = raw_input("Password: "******"Can't find tarball at that location, please check spelling"
    sys.exit(1)
outputfile = open(tarballName, "w")
if password:
    cipher = twofish.twofish()
    m = hashlib.md5()
    m.update(password)
    key = m.digest()
    cipher.setkey(key)
    cipher.decrypt_cfb_file(inputfile,outputfile)
else:
    blocksize = 1024 * 1024
    s = inputfile.read(blocksize)
    while s:
        outputfile.write(s)
        s = inputfile.read(blocksize)
inputfile.close()
outputfile.close()
os.chdir("/tmp")
if os.system("tar xfz " + tarballName) != 0: