⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cypher.h

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * cypher.h * * Encryption support classes. * * Portable Windows Library * * Copyright (c) 1993-1998 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: cypher.h,v $ * Revision 1.12  1999/03/09 08:01:46  robertj * Changed comments for doc++ support (more to come). * * Revision 1.11  1999/02/16 08:07:10  robertj * MSVC 6.0 compatibility changes. * * Revision 1.10  1998/09/23 06:19:24  robertj * Added open source copyright license. * * Revision 1.9  1997/10/10 10:44:01  robertj * Fixed bug in password encryption, missing string terminator. * * Revision 1.8  1996/11/16 10:50:24  robertj * Fixed bug in registration order form showing incorrect check code when have key. * * Revision 1.7  1996/07/15 10:29:38  robertj * Changed memory block cypher conversion functions to be void *. * Changed key types to be structures rather than arrays to avoid pinter/reference confusion by compilers. * * Revision 1.6  1996/03/17 05:47:00  robertj * Changed secured config to allow for expiry dates. * * Revision 1.5  1996/03/16 04:36:43  robertj * Redesign of secure config to accommodate expiry dates and option values passed in security key code. * * Revision 1.4  1996/02/25 02:52:46  robertj * Further secure config development. * * Revision 1.3  1996/01/28 14:16:11  robertj * Further implementation of secure config. * * Revision 1.2  1996/01/28 02:41:00  robertj * Removal of MemoryPointer classes as usage didn't work for GNU. * Added the secure configuration mechanism for protecting applications. * * Revision 1.1  1996/01/23 13:04:20  robertj * Initial revision * */#ifndef _PCYPHER#define _PCYPHER#ifdef __GNUC__#pragma interface#endif/** MD5 Message Digest. A class to produce a Message Digest for a block of text/data using the MD5 algorithm as defined in RFC1321 by Ronald Rivest of MIT Laboratory for Computer Science and RSA Data Security, Inc. */class PMessageDigest5 : public PObject{  PCLASSINFO(PMessageDigest5, PObject)  public:    /// Create a new message digestor    PMessageDigest5();    /// Begin a Message Digest operation, initialising the object instance.    void Start();    /** Incorporate the specified data into the message digest. */    void Process(      const PString & str      /// String to be part of the MD5    );    /** Incorporate the specified data into the message digest. */
    void Process(      const char * cstr        /// C String to be part of the MD5    );    /** Incorporate the specified data into the message digest. */
    void Process(      const PBYTEArray & data  /// Data block to be part of the MD5    );    /** Incorporate the specified data into the message digest. */
    void Process(      const void * dataBlock,  /// Pointer to data to be part of the MD5      PINDEX length            /// Length of the data block.    );
    /// Resultant 128 bit digest of input data.    class Code {      private:        PUInt32l value[4];      friend class PMessageDigest5;    };    /**    Complete the message digest and return the magic number result.    The parameterless form returns the MD5 code as a Base64 string.        @return       Base64 encoded MD5 code for the processed data.    */    PString Complete();    void Complete(      Code & result   /// The resultant 128 bit MD5 code    );    /** Encode the data in memory to and MD5 hash value. */    static PString Encode(      const PString & str      /// String to be encoded to MD5    );    /** Encode the data in memory to and MD5 hash value. */
    static void Encode(      const PString & str,     /// String to be encoded to MD5      Code & result            /// The resultant 128 bit MD5 code    );    /** Encode the data in memory to and MD5 hash value. */
    static PString Encode(      const char * cstr        /// C String to be encoded to MD5    );    /** Encode the data in memory to and MD5 hash value. */
    static void Encode(      const char * cstr,       /// C String to be encoded to MD5      Code & result            /// The resultant 128 bit MD5 code    );    /** Encode the data in memory to and MD5 hash value. */
    static PString Encode(      const PBYTEArray & data  /// Data block to be encoded to MD5    );    /** Encode the data in memory to and MD5 hash value. */
    static void Encode(      const PBYTEArray & data, /// Data block to be encoded to MD5      Code & result            /// The resultant 128 bit MD5 code    );    /** Encode the data in memory to and MD5 hash value. */
    static PString Encode(      const void * dataBlock,  /// Pointer to data to be encoded to MD5      PINDEX length            /// Length of the data block.    );    /** Encode the data in memory to and MD5 hash value.
    
    @return
       Base64 encoded MD5 code for the processed data.
    */
    static void Encode(      const void * dataBlock,  /// Pointer to data to be encoded to MD5      PINDEX length,           /// Length of the data block.      Code & result            /// The resultant 128 bit MD5 code    );  private:    void Transform(const BYTE * block);    /// input buffer    BYTE buffer[64];    /// state (ABCD)    DWORD state[4];    /// number of bits, modulo 2^64 (lsb first)    PUInt64 count;};/**This abstract class defines an encryption/decryption algortihm.
A specific algorithm is implemented in a descendent class.*/class PCypher : public PObject{  PCLASSINFO(PCypher, PObject)  public:
    /// Mechanism by which sequential blocks are linked.    enum BlockChainMode {      ElectronicCodebook,        ECB = ElectronicCodebook,      CypherBlockChaining,        CBC = CypherBlockChaining,      OutputFeedback,        OFB = OutputFeedback,      CypherFeedback,        CFB = CypherFeedback,      NumBlockChainModes    };  // New functions for class    /**Encode the data. */
    PString Encode(      const PString & str       /// Clear text string to be encoded.    );    /**Encode the data. */
    PString Encode(      const PBYTEArray & clear  /// Clear text binary data to be encoded.    );    /**Encode the data. */
    PString Encode(      const void * data,        /// Clear text binary data to be encoded.      PINDEX length             /// Number of bytes of data to be encoded.    );    /**Encode the data. */
    void Encode(      const PBYTEArray & clear, /// Clear text binary data to be encoded.      PBYTEArray & coded        /// Encoded data.    );    /**Encode the data.
    The data is encoded using the algorithm embodied by the descendent class
    and the key specifed in the construction of the objects instance.

    The first form takes a string and returns an encoded string. The second
    form takes arbitrary binary data bytes and returns an encoded string. In
    both cases the encoded string is always 7 bit printable ASCII suitable
    for use in mail systems etc.

    The final form takes and arbitrary block of bytes and encodes them into
    another block of binary data.
    
    @return
      encoded string.
    */
    void Encode(      const void * data,        // Clear text binary data to be encoded.      PINDEX length,            // Number of bytes of data to be encoded.      PBYTEArray & coded        // Encoded data.    );    /**Decode the data. */
    PString Decode(      const PString & cypher   /// Base64 Cypher text string to be decoded.    );    /**Decode the data. */
    BOOL Decode(      const PString & cypher,  /// Base64 Cypher text string to be decoded.      PString & clear          /// Clear text string decoded.    );    /**Decode the data. */
    BOOL Decode(      const PString & cypher,  /// Base64 Cypher text string to be decoded.      PBYTEArray & clear       /// Clear text binary data decoded.    );    /**Decode the data. */
    PINDEX Decode(      const PString & cypher,  /// Base64 Cypher text string to be decoded.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -