Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

 

pad and unpad byte array

Demonstrates using the pad and unpad methods of CkByteArray.

Download Chilkat C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C++ Libraries for VC++ 6.0 / Win32

void ChilkatSample(void)
    {

    unsigned char data_bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    CkByteData data;
    data.append(data_bytes, 10);

    //  These are the padding options for the "pad" method:
    //  0 = Each padding byte is the pad count (16 extra added if size is already a multiple of 16)
    //  1 = Random bytes except the last is the pad count (16 extra added if size is already multiple of 16)
    //  2 = Pad with random data. (If already a multiple of 16, no padding is added).
    //  3 = Pad with NULLs. (If already a multiple of 16, no padding is added).
    //  4 = Pad with SPACE chars(0x20). (If already a multiple of 16, no padding is added).

    //  We'll pad to a block size of 16 bytes.
    int blockSize;
    blockSize = 16;

    int paddingScheme;
    paddingScheme = 0;

    //  Pad, display the padded byte data, unpad, then re-display
    data.pad(blockSize,paddingScheme);
    printf("%s\n",data.getEncoded("hex"));
    data.unpad(16,paddingScheme);
    printf("%s\n",data.getEncoded("hex"));
    printf("----\n");

    paddingScheme = 1;
    //  Pad, display the padded byte data, unpad, then re-display
    data.pad(blockSize,paddingScheme);
    printf("%s\n",data.getEncoded("hex"));
    data.unpad(16,paddingScheme);
    printf("%s\n",data.getEncoded("hex"));
    printf("----\n");

    //  There is no unpadding with schemes 2,3, and 4
    unsigned char data2_bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    CkByteData data2;
    data2.append(data2_bytes, 10);
    paddingScheme = 2;
    //  Pad and display the padded byte data
    data2.pad(blockSize,paddingScheme);
    printf("%s\n",data2.getEncoded("hex"));
    printf("----\n");

    //  There is no unpadding with schemes 2,3, and 4
    unsigned char data3_bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    CkByteData data3;
    data3.append(data3_bytes, 10);
    paddingScheme = 3;
    //  Pad and display the padded byte data
    data3.pad(blockSize,paddingScheme);
    printf("%s\n",data3.getEncoded("hex"));
    printf("----\n");

    //  There is no unpadding with schemes 2,3, and 4
    unsigned char data4_bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    CkByteData data4;
    data4.append(data4_bytes, 10);
    paddingScheme = 4;
    //  Pad and display the padded byte data
    data4.pad(blockSize,paddingScheme);
    printf("%s\n",data4.getEncoded("hex"));
    printf("----\n");
    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser