Good afternoon to you all
I need help
I need a script that will allow to encrypt the system�s timestamp;
I have to use a pre-shared key to cipher the timestamp, so basically I need:
1st) cipher with a pre-shared key
2nd) encrypt the timestamp
3rd) encode on a base64
the output should be something like:
g_6iIMPST6ZXcc9Yk3jYtA==
I would really apreciate your help
See man crypt for 1 & 2.
The 'net is full of base 64 encode/decode tools. I wrote my own C decoder:
$ cat mysrc/base64dec.c
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
static int i, o ;
static int ostate = 0 ;
static void p_putchar( int c ){
//fprintf(stderr,"p_putchar(%d=%c)\n",c,c);
if ( EOF == putchar( c )){
if ( ferror( stdout )){
perror( "base64dec: stdout" );
exit( 1 );
}
exit( 0 );
}
}
static void newbits( int b ){
//fprintf(stderr,"newbits(%d), ostate %d, o %d, i %d=%c\n",b,ostate,o,i,i);
switch ( ostate ){
case 0:
o = b ;
ostate = 6 ;
return ;
case 6:
p_putchar( ( o << 2 ) | ( b >> 4 ) );
o = b & 15 ;
ostate = 4 ;
return ;
case 4:
p_putchar( ( o << 4 ) | ( b >> 2 ));
o = b & 3 ;
ostate = 2 ;
return ;
default:
p_putchar( ( o << 6 ) | b );
ostate = 0 ;
return ;
}
}
int main( int argc, char **argv ){
int v = 0 ;
if ( argc > 1
&& !strcmp( argv[1], "-v" )){
v = 1 ;
}
while ( EOF != ( i = getchar())){
if ( i > 'z' ){
continue ;
}
if ( i < '+' ){
continue ;
}
if ( i > 'Z' ){
if ( i >= 'a' ){
newbits( i - 'a' + 26 );
}
continue ;
}
if ( i >= 'A' ){
newbits( i - 'A' );
continue ;
}
if ( i > '9' ){
continue ;
}
if ( i >= '0' ){
newbits( i - '0' + 52 );
continue ;
}
if ( i == '/' ){
newbits( 63 );
continue ;
}
if ( i == '+' ){
newbits( 62 );
}
} /* end while getchar */
if ( ferror( stdin )){
perror( "base64dec: stdin" );
exit( 1 );
}
if ( ostate && v ){
fprintf( stderr,
"\nbase64dec: Warning: %d bits =%d left at EOF.\n",
ostate, o );
exit( 2 );
}
exit( 0 );
}
1 Like