PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my settings
my profile
Public Pastes
Untitled
22 sec ago
Memory leak in a s...
16 sec ago
Untitled
18 sec ago
chal1
33 sec ago
save jpg with lowe...
22 sec ago
XPath how to selec...
28 sec ago
WATCH GREY'S ANATO...
52 sec ago
Untitled
30 sec ago
New Paste
//WORKING #include <openssl/evp.h> #include <openssl/blowfish.h> #include <openssl/crypto.h> #include <openssl/bn.h> #include <openssl/pem.h> #include <stdio.h> #include <stdlib.h> #include <arpa/inet.h> int main(){ /*char * plaintext = "This is the plaintext to encrypt"; EVP_CIPHER_CTX *ctx; int err; const EVP_CIPHER *c; c=EVP_get_cipherbyname("RC4"); if (!c){printf("No Cipher");exit(0);} EVP_CIPHER_CTX_init(ctx); // err= EVP_EncryptInit_ex(ctx, */ char *filein ="original.txt"; char *fileout ="test.bin"; do_crypt(fileout,filein); } int do_crypt(char *outfile,char *filein) { int outlen, tmplen; long inlen; FILE *out,*in; unsigned char *intext,*cripted; //bad key, get better one unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; //bad IV , get better one unsigned char iv[] = {1,2,3,4,5,6,7,8}; in = fopen(filein,"rb"); fseek(in,0,SEEK_END); inlen=ftell(in); rewind(in); //get whole size, then return to begining. intext = (unsigned char*)malloc(sizeof(char *)*inlen); cripted = (unsigned char *)malloc(sizeof(char*)*inlen+8); //size of file + block size (Blowfish buffer is 64bits->8bytes fread(intext,1,inlen,in); //read the whole file to buffer. EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); if(!EVP_EncryptUpdate(&ctx, cripted, &outlen, intext, inlen)) { /* Error */ return 0; } /* Buffer passed to EVP_EncryptFinal() must be after data just * * encrypted to avoid overwriting it. * */ if(!EVP_EncryptFinal_ex(&ctx, cripted + outlen, &tmplen)) { /* Error */ return 0; } outlen += tmplen; EVP_CIPHER_CTX_cleanup(&ctx); /* Need binary mode for fopen because encrypted data is * * binary data. Also cannot use strlen() on it because * * it wont be null terminated and may contain embedded * * nulls. * */ out = fopen(outfile, "wb"); fwrite(cripted, 1, outlen, out); //char outp[outlen+1]; //&outp=outbuf; //outp[outlen+1='\0'; //printf(outp); fclose(out); fclose(in); return 1; } //DECRYPT #include <openssl/evp.h> #include <openssl/blowfish.h> #include <openssl/crypto.h> #include <openssl/bn.h> #include <openssl/pem.h> #include <stdio.h> #include <stdlib.h> #include <arpa/inet.h> int main(){ /*char * plaintext = "This is the plaintext to encrypt"; EVP_CIPHER_CTX *ctx; int err; const EVP_CIPHER *c; c=EVP_get_cipherbyname("RC4"); if (!c){printf("No Cipher");exit(0);} EVP_CIPHER_CTX_init(ctx); // err= EVP_EncryptInit_ex(ctx, */ char *filein ="test.bin"; do_decrypt(filein); } int do_decrypt(char *filein) { unsigned char *cripted; unsigned char * plain; int criptedlen, tmplen,plainlen,errcode; /* Bogus key and IV: we'd normally set these from * * another source. * */ long fileSize; unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; unsigned char iv[] = {1,2,3,4,5,6,7,8}; FILE *in,*out; //open file for read in = fopen(filein,"rb"); //see how long it is fseek (in , 0 , SEEK_END); fileSize =ftell(in); rewind(in); //allocate memory for file cripted = (char *) malloc(sizeof(char *)*fileSize); //decript buffer should be filesize + block size length //blowfish block size is 8bytes (64bits) plain = (char*) malloc(sizeof(char *)*fileSize + 8); fread(cripted,fileSize,1,in); //all file is loaded into cripted*) EVP_CIPHER_CTX ctx; //FILE *out; EVP_CIPHER_CTX_init(&ctx); EVP_DecryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); if(!EVP_DecryptUpdate(&ctx, plain , &plainlen,cripted,fileSize)) { /* Error */ printf("error 1"); return 0; } /* Buffer passed to EVP_EncryptFinal() must be after data just * * encrypted to avoid overwriting it. * */ if(!(errcode=EVP_DecryptFinal_ex(&ctx, plain + plainlen, &tmplen))) { /* Error */ printf("error 2, code %x %s",errcode,plain); return 0; } plainlen += tmplen; EVP_CIPHER_CTX_cleanup(&ctx); /* Need binary mode for fopen because encrypted data is * * binary data. Also cannot use strlen() on it because * * it wont be null terminated and may contain embedded * * nulls. * */ out = fopen("decripted.bin", "wb"); // printf("decrypted :%x",plain); fwrite(plain, 1, plainlen, out); fclose(in); fclose(out); return 1; }
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
HTML 5
Java
JavaScript
Lua
None
Perl
PHP
Python
Rails
-------------
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
ActionScript
ActionScript 3
Ada
ALGOL 68
Apache Log
AppleScript
APT Sources
ASM (NASM)
ASP
autoconf
Autohotkey
AutoIt
Avisynth
Awk
BASCOM AVR
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
C++ (with QT extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
ChaiScript
Clojure
Clone C
Clone C++
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
DCS
Delphi
Delphi Prism (Oxygene)
Diff
DIV
DOS
DOT
E
ECMAScript
Eiffel
Email
EPC
Erlang
F#
Falcon
FO Language
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
Game Maker
GDB
Genero
Genie
GetText
Go
Groovy
GwBasic
Haskell
HicEst
HQ9 Plus
HTML
HTML 5
Icon
IDL
INI file
Inno Script
INTERCAL
IO
J
Java
Java 5
JavaScript
jQuery
KiXtart
Latex
Liberty BASIC
Linden Scripting
Lisp
LLVM
Loco Basic
Logtalk
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
MagikSF
Make
MapBasic
MatLab
mIRC
MIX Assembler
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MPASM
MXML
MySQL
newLISP
None
NullSoft Installer
Oberon 2
Objeck Programming Langua
Objective C
OCalm Brief
OCaml
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
Pascal
PAWN
PCRE
Per
Perl
Perl 6
PHP
PHP Brief
Pic 16
Pike
Pixel Bender
PL/SQL
PostgreSQL
POV-Ray
Power Shell
PowerBuilder
ProFTPd
Progress
Prolog
Properties
ProvideX
PureBasic
PyCon
Python
q/kdb+
QBasic
R
Rails
REBOL
REG
Robots
RPM Spec
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SQL
SystemVerilog
T-SQL
TCL
Tera Term
thinBasic
TypoScript
Unicon
UnrealScript
Vala
VB.NET
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Winbatch
XBasic
XML
Xorg Config
XPP
YAML
Z80 Assembler
ZXBasic
Paste Expiration:
Never
10 Minutes
1 Hour
1 Day
1 Month
Paste Exposure:
Public
Unlisted
Private (members only)
Paste Name / Title:
Hello
Guest
Sign Up
or
Login
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login