PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFBCipher
Wrapper Class for the ICipher interface.
#include <SFBCipher.h.hpp>
class SFBCipher : public SFBBase;
SFMTYPEDEFWRAPPER(SFBCipher)

Inheritance diagram

 Inheritance diagram of SFBCipherClass

Version

BREW 2.0 BREW 2.1 BREW 3.1 BREW 4.0
O O O O

Reference

BREW API ICipher

Member

Public Functions
SInt32 Cipher( VoidConstPtr data , SInt32 dataSize , VoidPtr result , SInt32Ptr resultSize )
Encrypt or decrypt data using the key previously initialized.
SInt32 Cipher( SFXBufferConstRef data , SFXBufferPtr buffer )
Encrypt or decrypt data using the key previously initialized.
Void Flush( Void )
Use with block ciphers during the encryption process to pad the last unprocessed block with predetermined bytes to form a complete block. This function does nothing if the block is already complete (64-bits in DES).
SFCError Init( VoidConstPtr key , SInt32 keySize )
Initializes the key for encryption or decryption using ArcFour.
SFCError Init( SFXBufferConstRef key )
Initializes the key for encryption or decryption using ArcFour.
static
SFBCipherSmp
NewInstance( AEECLSID clsid , SFCErrorPtr exception = null )
Create a new SFBCipher instance.
Protected Functions
static
SFBBaseSmp
FactoryByCreate( AEECLSID id , SFCErrorPtr exception = null ) (inherits from SFBBase)
Create the instance for the specified ClassID's interface.
static
SFBBaseSmp
FactoryByQuery( SFBQuerySmpConstRef query , AEECLSID id , SFCErrorPtr exception = null ) (inherits from SFBBase)
Create the instance for the specified ClassID's interface using the SFBQuery instance.

SFBCipher::Cipher
Encrypt or decrypt data using the key previously initialized.
[ public ]
SInt32 Cipher(
    VoidConstPtr data      // pointer to data to be encrypted/decrypted
    SInt32 dataSize        // input data size in bytes
    VoidPtr result         // buffer to receive encrypted/decrypted data
    SInt32Ptr resultSize   // size of output in bytes
);
[ public ]
SInt32 Cipher(
    SFXBufferConstRef data   // pointer to data to be encrypted/decrypted
    SFXBufferPtr buffer      // buffer to receive encrypted/decrypted data.
                             // buffer size is set to SInt32 when call
);

Example

Encrypt/Decrypt data by common key.

// deside the key for Encrypting/Decrypting
char        key[]    = {"Key Cipher"};
SInt32      keySize = STRLEN(key);

// create Interface of SFBCipher
// encrypt data by ArcFour (RC4 interconverting).
SFBCipherSmp cipher = SFBCipher::NewInstance(AEECLSID_ARC4);

// set Decrypted key
if (SUCCESS == cipher->Init(key, keySize))
{
    SFXAnsiString   srcData("Cipher");
    SInt32          size    = src_data.GetLength() + 1;
    VoidPtr         encData = MALLOC(size);
    VoidPtr         decData = MALLOC(size);

    // output the un-Decrypted data
    DBGPRINTF("srcData -- %s", srcData.GetBuffer());

    // decrypt it
    cipher->Cipher(srcData.GetBuffer(), size, encData, &size);
    // output the Decrypted data
    DBGPRINTF("encData -- %s", (char*)encData);

    // set Decrypted key
    cipher->Init(key, keySize);
    // decrypt it
    cipher->Cipher(encData, size, decData, &size);
    // output the Decrypted data
    DBGPRINTF("decData -- %s", (char*)decData);

    // release Buffer.
    FREE(encData);
    FREE(decData);
}

Reference

BREW API ICIPHER_Cipher


SFBCipher::Flush
Use with block ciphers during the encryption process to pad the last unprocessed block with predetermined bytes to form a complete block. This function does nothing if the block is already complete (64-bits in DES).
[ public ]
Void Flush(Void);

Description

[Tip] Tip

Before BREW SDK 2.1 , block encryption algorithm is not supported in ICipher Interface. So, it is not necessary tu use this function.

Reference

BREW API ICIPHER_Flush


SFBCipher::Init
Initializes the key for encryption or decryption using ArcFour.
[ public ]
SFCError Init(
    VoidConstPtr key   // pointer to key
    SInt32 keySize     // key size in bytes
);
[ public ]
SFCError Init(
    SFXBufferConstRef key   // pointer to key
);

Reference

BREW API ICIPHER_Init


SFBCipher::NewInstance
Create a new SFBCipher instance.
[ public, static ]
SFBCipherSmp NewInstance(
    AEECLSID clsid                 // ClassID for the encrypted interface
    SFCErrorPtr exception = null   // Error
);

Description

Create an encrypted interface, return it as ICipher. ClassID can be specified as below. Homologous algorithm will be used for specified ClassID.

AEECLSID_ARC4
AEECLSID_DES_ENCRYPT
AEECLSID_DES_DECRYPT
AEECLSID_3DES_ENCRYPT
AEECLSID_3DES_DECRYPT