C++ Base64编码解码、MD5及TEA加密解密
Crypto.h以及Crypto.cpp
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
#pragma once
#ifndef __CCRYPTO__H__INCLUDED__ #include <string> #define CONST const // BASE64 public: // 63rd char used for Base64 code // 64th char used for Base64 code // Char used for padding public: // Encodes binary data to Base64 code // Decodes Base64 code to binary data // Returns maximum size of decoded data based on size of Base64 code. // Returns maximum length of Base64 code based on size of uncoded data. }; /////////////////////////////////////TEA加密////////////////////////////////////////////////// AS_PUBLIC CLASS CryptoTEA public: /// <summary> /// <summary> /// <summary> /// <summary> /// <summary> /// <summary> /// <summary> /// <summary> }; //////////////////////////////////////// MD5/////////////////////////////////////////// /* MD5 context. */ /* F, G, H and I are basic MD5 functions. */ /* ROTATE_LEFT rotates x left n bits. */ /* class CryptoMD5 public: /* Note: Replace "for loop" with standard memcpy if possible. */ /* /* /* MD5 basic transformation. Transforms state based on block. */ /* MD5 initialization. Begins an MD5 operation, writing a new context. */ /* /* static CString MD5String (std::wstring Source); }; |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
#include "stdafx.h"
#include "Crypto.h" ] = // Encodes binary data to Base64 code wstring result; // output buffer which holds code during conversation // charachers used by Base64 // mask - first six bits // used as temp 24-bits buffer // coversation is done by taking three bytes at time of input data int temp // get first byte and puts it at MSB position in temp buffer // more data left? //------------------------ // extract first and second six-bit value from temp buffer outCode.clear(); } // Decodes Base64 code to binary data // used as temp 24-bits buffer // number of decoded bytes ; i < codeLength; i++ ) wchar_t x = inCode[ i ]; // converts base64 character to six-bit value // padding chars are not decoded and written to output buffer // temp buffer is full or end of code is reached // restarts temp buffer // when padding char is reached it is the end of code return j; } // Returns maximum size of decoded data based on size of Base64 code. // Returns maximum length of Base64 code based on size of uncoded data. // output code size must be multiple of 4 bytes return len; /// <summary> /// <summary> // sum = delta << 5, in general sum = delta * n /// <summary> /// 加密数据 return nBufLen; /// <summary> /// 解密 /// <summary> // 确定缓冲区长度 // 进行加密 // 构造结果 // 释放内存并返回 /// <summary> if( chr >= 'a' && chr <= 'f' ) if( chr >= 'A' && chr <= 'F' ) // 无效字符 /// <summary> //============================================================================== ); // 无效参数 // 检查输入是否有效 // 输入必须是进制数0-9 A-F // 检查是否为A-F // 检查是否为A-F // 无效输入 //============================================================================== //============================================================================== // 前面字节为长度信息 // 准备结果 // 返回 /// <summary> /* Note: Replace "for loop" with standard memset if possible. */ ; i < len; i++) /* Note: Replace "for loop" with standard memcpy if possible. */ ; i < len; i++) /* ) { /* ) /* MD5 basic transformation. Transforms state based on block. */ Decode(x, block, ); /* Round 1 */ /* Round 2 */ /* Round 3 */ /* Round 4 */ state[] += a; /* Zeroize sensitive information. */ /* MD5 initialization. Begins an MD5 operation, writing a new context. */ /* /* Compute number of bytes mod 64 */ /* Update number of bits */ partLen = - index; /* Transform as many times as possible. */ ) index = ; /* Buffer remaining input */ /* /* Save number of bits */ /* Pad out to 56 mod 64. */ /* Append length (before padding) */ /* Store state in digest */ /* Zeroize sensitive information. */ BYTE* pSource = ]; WideCharToMultiByte(CP_ACP, , NULL, NULL); MD5_CONTEXT context; delete []pSource; }; // 保存校验码,个数+null-terminal |
C++ Base64编码解码、MD5及TEA加密解密的更多相关文章
- qt md5加密,base64编码解码
qt md5加密,base64编码解码 md5加密 QByteArray data = "12121221"; data += "asdfas"; QByteA ...
- 利用openssl进行BASE64编码解码、md5/sha1摘要、AES/DES3加密解密
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 网络安全——Base64编码、MD5、SHA1-SHA512、HMAC(SHA1-SHA512)哈希
据说今天520是个好日子,为什么我想起的是502.500.404这些?还好服务器没事! 一.Base64编码 Base64编码要求把3个8位字节(3*8=24)转化为4个6位的字节(4*6=24),之 ...
- 《PHP 实现 Base64 编码/解码》笔记
前言 早在去年 11 月底就已经看过<PHP 实现 Base64 编码/解码>这篇文章了,由于当时所掌握的位运算知识过于薄弱,所以就算是看过几遍也是囫囵吞枣一般,不出几日便忘记了其滋味. ...
- OpenSSL 使用 base64 编码/解码
简述 关于 OpenSSL 的介绍及安装请参见:Windows下编译OpenSSL 下面主要介绍有关 OpenSSL 使用 base64 编码/解码. 简述 编码解码 更多参考 编码/解码 #incl ...
- Javascript中Base64编码解码的使用实例
Javascript为我们提供了一个简单的方法来实现字符串的Base64编码和解码,分别是window.btoa()函数和window.atob()函数. 1 var encodedStr = win ...
- Atitit. 二进制数据ascii表示法,与base64编码解码api 设计标准化总结java php c#.net
Atitit. 二进制数据ascii表示法,与base64编码解码api 设计标准化总结java php c#.net 1. Base64编码, 1 1.1. 子模式 urlsafe Or url ...
- Atitit. 二进制数据ascii表示法,与base64编码解码api 设计标准化总结java php c#.net
Atitit. 二进制数据ascii表示法,与base64编码解码api 设计标准化总结java php c#.net 1. Base64编码,1 1.1. 子模式 urlsafe Or url u ...
- delphi Base64编码/解码及数据压缩/解压知识
一.Base64编码/解码 一般用到的是Delphi自带的单元EncdDecd,当然还有第三方提供的单元或控件,其中我所接触到的认为比较好的有Indy的TIdMimeEncode / TIdMimeD ...
随机推荐
- php遍历文件夹代码实现
<?php //遍历文件夹 function my_scandir($dir){ $files = array(); if (is_dir($dir)){ if($handle = opendi ...
- C++11 std::async 包装实体店::packaged_task
更好的方式 C++11中提供了操作多线程的高层次特性. std::packaged_task 包装的是一个异步操作,相当与外包任务,好比我大阿里把电话客服外包给某某公司. std::future 提供 ...
- SugarCRM如何检查控制器权限?
SugarController定义了一个实例变量$hasAccess,布尔值,默认为true.该实例变量指示使用者是否有执行摸个action的权限: class SugarController{ /* ...
- sql中判断某个字符串是否包含一个字符串
如果想从SQL Server中查询包含某个关键字的东东,怎么查询呢? 一般有两个方法: 1.用like——select * from tablename where field1 like like ...
- (七)Oracle学习笔记—— 游标
1.游标简介 游标用来处理从数据库中检索的多行记录(使用SELECT语句).利用游标,程序可以逐个地处理和遍历一次检索返回的整个记录集. 为了处理SQL语句,Oracle将在内存中分配一个区域,这就是 ...
- angular过滤器使用 自定义过滤器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- visual studio 2017无建模项目?
教一跨行同事学C#,我想从基础的讲一下,也就是最基本的面象对象分析与设计(OOAD),我直接打开我最新安装的 visual studio 2017.准备建一个“建模项目”.结果发现死活找不到?打开一个 ...
- Spring Boot(三):logback打印日志
springboot对logback的支持是非常好的,不需要任何配置,只需要在resource下加logback.xml就可以实现功能直接贴代码: <?xml version="1.0 ...
- HR问“预期薪资是多少”,这么说能加薪zz
每年过完节,收好上一年的年终奖,身边人就开始蠢蠢欲动,招聘市场也异常火爆,节前各种裁员的新闻,过了个节都变成了“我们还要继续招人”. 年景不好,人才更是成了紧俏货.可现实中,我却发现,优质的人才未必能 ...
- atitit.系统架构图 的设计 与工具 attilax总结
atitit.系统架构图 的设计 与工具 attilax总结 1. 架构图的4个版式(标准,(左右)悬挂1 2. 架构图的层次结构(下属,同事,助手)1 3. wps ppt1 4. 使用EDraw画 ...