Hello
I have a system that uses a CFM100 drive with a CR1000 datalogger, that is in a remote location. As I have some concern with the data that are being collected, I wonder if there is any way to encrypt the data being written to the data card (2Gb) to prevent access to the data if the card is stolen. I am writing data at 1Hz.
Thanks for your time
Jose Rodrigues
There is no built in function to do this. (Although you will shortly be able to encrypt communications.)
It would not be difficult to write your own simple algorithm to "encrypt" the data to some degree. Techniques you could use might be: applying a fixed or changing offset/multiplier to the data values stored (perhaps incremented by channel or perhaps based on time of day) OR converting the data to integers and XOR'ing them with a constant or variable before storage. However you would need to encrypt the logger program to stop the technique used being seen in the event the logger was stolen too. (Encryption of programs is something you can already do). You would also need to write you own program to decrypt the data after collection.
Thanks Aps
I will try this method. I dont encrypt my code but i have all the security levels active.
Cheers
* Last updated by: TaCaPica on 7/3/2013 @ 5:16 AM *
I had to try implementing an encryption algorithm using CRBasic. It sounded like a fun thing to try. The following code could be made better. Anyway, it is based on using the information I found on Wikipedia about TEA encryption. It is simple enough that one should be able to implement a decryption program on a PC. The password is 32 bytes, entered as an array of 4 longs. The program encrypts the last file generated by TableFile. More code needs to be added to do the file management tasks.
Public PTemp, batt_volt
Public OutStat As Boolean
Public LastFileName As String * 32
Public Secret(4) As Long = {1,2,3,4}
Public EnC As Boolean
Public numBytes As Long
Sub teaEcrypt(dest(2) As Long, src(2) As Long, key(4) As Long)
  Dim v0 As Long, v1 As Long
  Dim k0 As Long, k1 As Long, k2 As Long, k3 As Long
  Dim sum As Long, i As Long
  Dim delta As Long = &h9e3779b9
  sum = 0
  v0 = src(1) : v1 = src(2)
  k0 = key(1) : k1 = key(2) : k2 = key(3) : k3 = key(4)
  For i = 0 To 31
    sum += delta
    v0 += ((v1 << 4) + k0) XOR (v1 + sum) XOR ((v1 >> 5) + k1)
    v1 += ((v0 << 4) + k2) XOR (v0 + sum) XOR ((v0 >> 5) + k3)
  Next i
  dest(1) = v0 : dest(2) = v1
EndSub
Sub teaDcrypt(dest(2) As Long, src(2) As Long, key(4) As Long)
  Dim v0 As Long, v1 As Long
  Dim k0 As Long, k1 As Long, k2 As Long, k3 As Long
  Dim sum As Long, i As Long
  Dim delta As Long = &h9e3779b9
  sum = &hc6ef3720
  v0 = src(1) : v1 = src(2)
  k0 = key(1) : k1 = key(2) : k2 = key(3) : k3 = key(4)
  For i = 0 To 31
    v1 -= ((v0 << 4) + k2) XOR (v0 + sum) XOR ((v0 >> 5) + k3)
    v0 -= ((v1 << 4) + k0) XOR (v1 + sum) XOR ((v1 >> 5) + k1)
    sum -= delta
  Next i
  dest(1) = v0 : dest(2) = v1
EndSub
Sub teaFileEncrypt(srcFile As String, dstFile As String, key(4) As Long, Optional bytes As Long = 0)
  Dim srcHand As Long, dstHand As Long
  Dim s(2) As Long, d(2) As Long
  Dim nb As Long
  srcHand = FileOpen (srcFile,"rb",0)
  dstHand = FileOpen (dstFile,"wb",0)
  bytes = 0
  Do
    Move (s,2,0,1)
    Move (d,2,0,1)
    nb = FileRead (srcHand,s,8)
    If nb > 0 Then
      bytes = bytes + nb
      teaEcrypt(d,s,key)
      FileWrite (dstHand,d,8)
    Else
      ExitDo
    EndIf
  Loop
  FileClose (srcHand)
  FileClose (dstHand)
EndSub
Sub teaFileDecrypt(srcFile As String, dstFile As String, key(4) As Long, Optional bytes As Long = -1)
  Dim srcHand As Long, dstHand As Long
  Dim s(2) As Long, d(2) As Long
  Dim nb As Long, cnt As Long
  srcHand = FileOpen (srcFile,"rb",0)
  dstHand = FileOpen (dstFile,"wb",0)
  cnt = bytes
  Do
    Move (s,2,0,1)
    Move (d,2,0,1)
    nb = FileRead (srcHand,s,8)
    If nb > 0 Then
      teaDcrypt(d,s,key)
      If cnt > 7 OR cnt < 0 Then
        FileWrite (dstHand,d,8)
        cnt = cnt - 8
      Else
        FileWrite (dstHand,d,cnt)
      EndIf
    Else
      ExitDo
    EndIf
  Loop
  FileClose (srcHand)
  FileClose (dstHand)
EndSub
DataTable (Test,1,1000)
  DataInterval (0,15,Sec,10)
  TableFile ("USR:Test_",8,3,0,1,Min,OutStat,LastFileName)
  Minimum (1,batt_volt,FP2,0,False)
  Sample (1,PTemp,FP2)
EndTable
BeginProg
  SetStatus("USRDriveSize",1000000)
  Scan (1,Sec,0,0)
    PanelTemp (PTemp,250)
    Battery (batt_volt)
    CallTable Test
    If OutStat Then EnC = TRUE
  NextScan
  SlowSequence
  Do
    Delay (1,1,Sec)
    If EnC Then
      teaFileEncrypt(LastFileName, Replace(LastFileName,".dat",".dat.enc"), Secret, numBytes)
      EnC  = FALSE
    EndIf
  Loop
  EndSequence
EndProg