This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> Place.query.filter(Place.lat - 37.52 > 0.01).count() | |
2011-12-10 02:26:57,731 INFO sqlalchemy.engine.base.Engine SELECT count(*) AS count_1 | |
FROM ... | |
FROM place | |
WHERE aes_decrypt(unhex(place.encrypted_lat), %s) - %s > %s) AS anon_1 | |
2011-12-10 02:26:57,731 INFO sqlalchemy.engine.base.Engine ('1234567890123456', 37.520000000000003, 0.01) | |
8L | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> Place.query.get(1).lat | |
37.520410699999999 | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if str(db.engine.url).find('mysql://') >= 0: | |
import EncryptedLocationMixIn as LocationMixIn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lat.setter | |
def lat(self, value): | |
self.encrypted_lat = aes_encrypt(str(value)[:16]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lat.expression | |
def lat(cls): | |
decrypted = expr.func.aes_decrypt( | |
expr.func.unhex(cls.encrypted_lat), aes_key) | |
return cast(decrypted, db.Float(25)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@hybrid_property | |
def lat(self): | |
return float(aes_decrypt(self.encrypted_lat)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EncryptedLocationMixIn(object): | |
encrypted_lat = db.Column(db.String(64), nullable=True) | |
encrypted_lng = db.Column(db.String(64), nullable=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Cipher import AES | |
import binascii | |
aes_key = '1234567890123456' # it must be 128-bit. | |
def aes_encrypt(data): | |
cipher = AES.new(aes_key) | |
expected_length = 16 * ((len(data) / 16) + 1) | |
padding_length = expected_length - len(data) | |
data = data + chr(padding_length) * padding_length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationMixIn(object): | |
lat = db.Column(db.Float(25), nullable=True) | |
lng = db.Column(db.Float(25), nullable=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "hi!!!" |
NewerOlder