Example #1
0
void pawsKeySelectBox::SetText(const char * keyText)
{
    text = keyText;
    if (text.IsEmpty())
    {
        SetKey(0,0);
        return;
    }

    size_t spaceChar;
    while ((spaceChar = text.FindFirst(' ')) > 0)
        text.DeleteAt(spaceChar);

    utf32_char keyCode;
    utf32_char cookedCode;
    csKeyModifiers mods;

    if (!csInputDefinition::ParseKey(PawsManager::GetSingleton().GetEventNameRegistry (),
	  text, &keyCode, &cookedCode, &mods))
    {
        SetKey(0,0);
        return;
    }

    modifiers = 0;
    if (mods.modifiers[csKeyModifierTypeAlt] != 0)
        modifiers |= CSMASK_ALT;
    if (mods.modifiers[csKeyModifierTypeCtrl] != 0)
        modifiers |= CSMASK_CTRL;
    if (mods.modifiers[csKeyModifierTypeShift] != 0)
        modifiers |= CSMASK_SHIFT;

    SetKey(keyCode, modifiers);
}
Example #2
0
int main()
{
	int i=0; 
	char MesHex[16]={0};         // 16个字符数组用于存放 64位16进制的密文
 	char MyKey[8]={0};           // 初始密钥 8字节*8
	char YourKey[8]={0};         // 输入的解密密钥 8字节*8
	char MyMessage[8]={0};       // 初始明文 
	
/*-----------------------------------------------*/

	printf("Welcome! Please input your Message(64 bit):\n");
	gets(MyMessage);            // 明文
	printf("Please input your Secret Key:\n");
	gets(MyKey);                // 密钥

	while(MyKey[i]!='\0')        // 计算密钥长度
	{
		i++;
	}

	while(i!=8)                  // 不是8 提示错误
	{
		printf("Please input a correct Secret Key!\n");
		gets(MyKey);
		i=0;
		while(MyKey[i]!='\0')    // 再次检测
		{
			i++;
		}
	}

	SetKey(MyKey);               // 设置密钥 得到子密钥Ki
	
	PlayDes(MesHex,MyMessage);   // 执行DES加密

	printf("Your Message is Encrypted!:\n");  // 信息已加密
	for(i=0;i<16;i++)           
	{
		printf("%c ",MesHex[i]);
	}
	printf("\n");
	printf("\n");
	
	printf("Please input your Secret Key to Deciphering:\n");  // 请输入密钥以解密
	gets(YourKey);                                         // 得到密钥
	SetKey(YourKey);                                       // 设置密钥

	KickDes(MyMessage,MesHex);                     // 解密输出到MyMessage
	
	printf("Deciphering Over !!:\n");                     // 解密结束
	for(i=0;i<8;i++)
	{
		printf("%c ",MyMessage[i]);
	}
	printf("\n");
	system("pause");
		
/*------------------------------------------------*/	
}
Example #3
0
status_t
AESAlgorithm::SetCompleteKey(ThreadContext& context, const uint8* key,
	size_t keyLength)
{
	if (fMode == MODE_LRW)
		return SetKey(context, key + KEY_SIZE, KEY_SIZE);

	return SetKey(context, key, KEY_SIZE);
}
PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
{
    if (s) {
        SetSize(s);
        SetKey(k);
    }
}
Example #5
0
//-------------------------------------------------------------------------------------------------
bool sdAnimUIntTrack::Load(Engine::Util::sdLuaReadUtil& kLuaStream)
{
	if (!kLuaStream.ReadData("TrackFlag", m_iFlags))
	{
		m_iFlags = IKey::E_KEY_FLAG_CONSTANT;
	}

	kLuaStream.BeginReadNode("Value");
	if (kLuaStream.IsNodeValid())
	{
		int t = kLuaStream.LoopReset();
		while (kLuaStream.LoopNext(t))
		{
			sdUIntKey kKey;
			kLuaStream.ReadData("Time",  kKey.m_fTime);
			kLuaStream.ReadData("Flags", kKey.m_iFlags);
			kLuaStream.ReadData("UInt",  kKey.m_uiValue);

			int iIndex = CreateKey(kKey.m_fTime);
			SetKey(iIndex, &kKey);

			kLuaStream.LoopInnerEnd();
		}
	}
	kLuaStream.EndReadNode();

	return true;
}
Example #6
0
//-------------------------------------------------------------------------------------------------
void sdAnimUIntTrack::SetValue(float fTime, uint uiValue) 
{
	sdUIntKey kKey(fTime, IKey::E_KEY_FLAG_CONSTANT, uiValue);
	int iIndex = FindKey(fTime);
	if (iIndex == -1)
	{
		int iKeyNum = GetNumKeys();
		SetNumKeys(iKeyNum + 1);
		SetKey(iKeyNum, &kKey);
		SortKeys();
	}
	else
	{
		SetKey(iIndex, &kKey);
	}
}
Example #7
0
//! Use key + salt to encrypt the header, and write it to disk.
status_t
VolumeCryptContext::_WriteHeader(int fd, const uint8* key, uint32 keyLength,
	off_t headerOffset, uint8* buffer)
{
	uint8 diskKey[DISK_KEY_SIZE];
	derive_key(key, keyLength, buffer, PKCS5_SALT_SIZE, diskKey, DISK_KEY_SIZE);

	status_t status = Init(ALGORITHM_AES, MODE_XTS, diskKey, DISK_KEY_SIZE);
	if (status != B_OK)
		return status;

	true_crypt_header& header = *(true_crypt_header*)&buffer[PKCS5_SALT_SIZE];
	Encrypt((uint8*)&header, BLOCK_SIZE - PKCS5_SALT_SIZE);

	ssize_t bytesWritten = write_pos(fd, headerOffset, buffer, BLOCK_SIZE);
	if (bytesWritten < 0)
		return errno;

	// use the decrypted header to init the volume encryption

	Decrypt((uint8*)&header, BLOCK_SIZE - PKCS5_SALT_SIZE);
	SetKey(header.disk_key, sizeof(header.disk_key));

	return B_OK;
}
Example #8
0
status_t
CryptContext::Init(encryption_algorithm algorithm, encryption_mode mode,
	const uint8* key, size_t keyLength)
{
	_Uninit();

	ThreadContext threadContext;

	fAlgorithm = create_algorithm(algorithm);
	if (fAlgorithm == NULL)
		return B_NO_MEMORY;

	status_t status = fAlgorithm->Init(threadContext);
	if (status != B_OK)
		return status;

	fMode = create_mode(mode);
	if (fMode == NULL)
		return B_NO_MEMORY;

	status = fMode->Init(threadContext, fAlgorithm);
	if (status != B_OK)
		return status;

	fThreadContexts = new(std::nothrow) ThreadContext*[sThreadCount];
	if (fThreadContexts == NULL)
		return B_NO_MEMORY;

	for (int32 i = 0; i < sThreadCount; i++) {
		fThreadContexts[i] = new ThreadContext(threadContext);
	}

	return SetKey(key, keyLength);
}
Example #9
0
/*----------------------------------------------------------------------
|       AP4_IsmaKeyMap::KeyEntry::KeyEntry
+---------------------------------------------------------------------*/
AP4_IsmaKeyMap::KeyEntry::KeyEntry(AP4_UI32        track_id, 
                                   const AP4_UI08* key, 
                                   const AP4_UI08* salt /* = NULL */) :
    m_TrackId(track_id)
{
    SetKey(key, salt);
}
Example #10
0
ULONG DesCode( void *Out, const void *In, ULONG Length, const void *Key, ULONG KeyLength, ULONG Type )
{
    register int Iter;
    register int Count;
    ULONG Is3DES;
    ULONG Left;
    const UCHAR *UKey;
    register UCHAR *UOut;
    register const UCHAR *UIn;
    DES_SUBKEY SubKey[2]; /* 16 loop sub key */

    if ( Out == NULL || In == NULL || Key == NULL || Length == 0 )
        return FALSE;

    UKey = ( const UCHAR* )Key;
    SetKey( SubKey, &Is3DES, UKey, KeyLength );

    Left = Length & 7;
    Length &= ~7;
    if ( !Is3DES )
    {
        /* 1DES */
        UOut = ( UCHAR* )Out;
        UIn = ( const UCHAR* )In;
        for ( Iter = 0, Count = Length >> 3; Iter < Count; Iter++, UOut += 8, UIn += 8 )
            DES( UOut, UIn, &SubKey[0], Type );
        while ( Left )
        {
            *UOut = ( UCHAR ) ( *UIn ^ DEFAULT_XOR ^ UKey[Left % KeyLength] );
            UIn++;
            UOut++;
            Left--;
        }
    }
Example #11
0
bool SecMsgCrypter::SetKey(const std::vector<uint8_t> &vchNewKey, const uint8_t *chNewIV)
{
    if (vchNewKey.size() != SMSG_CRYPTO_KEY_SIZE)
        return false;

    return SetKey(&vchNewKey[0], chNewIV);
};
Example #12
0
void CServerDesc::Serialize( CAr & ar )
{
	if( ar.IsStoring() )
	{
		ar << m_uKey;
		ar << (short)m_lspJurisdiction.size();
		for( list<CJurisdiction*>::iterator i = m_lspJurisdiction.begin(); i != m_lspJurisdiction.end(); ++i )
		{
			ar << (*i)->m_dwWorldID;
			ar << (*i)->m_rect;
			ar << (*i)->m_wLeft;
			ar << (*i)->m_wRight;
		}
		ar.WriteString( m_szAddr );
	}
	else
	{
		u_long uKey;
		ar >> uKey;
		SetKey( uKey );
		short nSize;
		ar >> nSize;
		for( int i =0; i < nSize; i++ )
		{
			CJurisdiction* pJurisdiction	= new CJurisdiction;
			ar >> pJurisdiction->m_dwWorldID;
			ar >> pJurisdiction->m_rect;
			ar >> pJurisdiction->m_wLeft;
			ar >> pJurisdiction->m_wRight;
			m_lspJurisdiction.push_back( pJurisdiction );
		}
		ar.ReadString( m_szAddr );
	}
}
Example #13
0
int __stdcall iIOCtl(int cmd, void *data)
{
	int result = 0;


	switch(cmd)
	{
	case 0:
		ChangeCard();
		break;

	case 1:
		InitCard();
		break;

	case 2:
		SetKey((struct CreateKeyInfoS *)data);
		break;

	case 3:
		ChangeVirtualFile((char *)data);
		break;

	default:
		break;
	}

	return result;
}
Example #14
0
CStringTable::CStringTable(WORD wLang, WORD wCodePage)
{
	CString strKey;
	strKey.Format(_T("%04x%04x"), wLang, wCodePage);

	SetKey(strKey);
}
Example #15
0
File: Chan.cpp Project: jimloco/znc
CChan::CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig, CConfig *pConfig) {
	m_sName = sName.Token(0);
	m_sKey = sName.Token(1);
	m_pNetwork = pNetwork;

	if (!m_pNetwork->IsChan(m_sName)) {
		m_sName = "#" + m_sName;
	}

	m_bInConfig = bInConfig;
	m_Nick.SetNetwork(m_pNetwork);
	m_bDetached = false;
	m_uBufferCount = m_pNetwork->GetUser()->GetBufferCount();
	m_bKeepBuffer = m_pNetwork->GetUser()->KeepBuffer();
	m_bDisabled = false;
	Reset();

	if (pConfig) {
		CString sValue;
		if (pConfig->FindStringEntry("buffer", sValue))
			SetBufferCount(sValue.ToUInt(), true);
		if (pConfig->FindStringEntry("keepbuffer", sValue))
			SetKeepBuffer(sValue.ToBool());
		if (pConfig->FindStringEntry("detached", sValue))
			SetDetached(sValue.ToBool());
		if (pConfig->FindStringEntry("autocycle", sValue))
			if (sValue.Equals("true"))
				CUtils::PrintError("WARNING: AutoCycle has been removed, instead try -> LoadModule = autocycle " + sName);
		if (pConfig->FindStringEntry("key", sValue))
			SetKey(sValue);
		if (pConfig->FindStringEntry("modes", sValue))
			SetDefaultModes(sValue);
	}
}
Example #16
0
STDMETHODIMP CDecoder::Init()
{
  CalcKey_and_CheckPassword();
  RINOK(SetKey(_key, kAesKeySize));
  RINOK(SetInitVector(_iv, AES_BLOCK_SIZE));
  return CAesCbcCoder::Init();
}
// ----------------------------------------------------------------------------
// CSdpMediaField::DoInternalizeL
// ----------------------------------------------------------------------------
//
void CSdpMediaField::DoInternalizeL(RReadStream& aStream)
{
    RStringF media = iPool.OpenFStringL(GetTokenFromStreamL(aStream));
    CleanupClosePushL(media);
    SetMediaL(media);
    CleanupStack::Pop();//media
    media.Close();
    TUint32 port = aStream.ReadUint32L();
    //SetPortL(aStream.ReadUint32L());
    TUint flag = aStream.ReadUint8L();
    if(flag)
    {
        SetPortCountL(aStream.ReadUint32L());
    }
    RStringF protocol =iPool.OpenFStringL(GetTokenFromStreamL(aStream));
    CleanupClosePushL(protocol);
    SetProtocolL(protocol);
    CleanupStack::Pop();//protocol
    protocol.Close();
    SetPortL(port);
    SetFormatListL(GetTokenFromStreamL(aStream));
    SetInfoL(GetTokenFromStreamL(aStream));
    SdpCodecTemplate<CSdpConnectionField>::InternalizeArrayL(*iConnectionFields,
            aStream);
    SdpCodecTemplate<CSdpBandwidthField>::InternalizeArrayL(*iBandwidthFields,
            aStream);
    if(aStream.ReadUint8L())
    {
        SetKey(CSdpKeyField::InternalizeL(aStream));
    }
    SdpCodecTemplate<CSdpAttributeField>::InternalizeArrayL(*iAttributeFields,
            aStream);
    SdpCodecTemplate<CSdpFmtAttributeField>::InternalizeArrayL(*iFmtAttrFields,
            aStream);
}
Example #18
0
SecurityClientSSL::SecurityClientSSL(	Address& Address,
										std::string certFile,
										std::string keyFile,
										std::string trustFile,
										std::string password,
										securityMode method) :
	SecurityClient(Address),
	itsSecurityMode(method),
	itsCertificate(new Certificate()), itsKey(new Key()), itsTrust(new Trust())
{
	SetCertificate(certFile);
	SetKey(keyFile);
	SetTrust(trustFile);
	itsPassword = password;
	libsslInit();

	itsCTX = SSLWrap::SSL_CTX_new(GetMethod()); /* create new context from method */
	if (itsCTX == NULL) {
		throw_SSL("SSL_CTX_new failed");
	}

	SSLWrap::SSL_CTX_set_default_passwd_cb(itsCTX, passwordCallback);
	if (itsPassword.length() >= 4)
		SSLWrap::SSL_CTX_set_default_passwd_cb_userdata(itsCTX, this);

	itsCertificate->SetContext(itsCTX);
	itsKey->SetContext(itsCTX);
	itsTrust->SetContext(itsCTX);

	itsCertificate->Apply();
	itsKey->Apply();
	itsTrust->Apply();

	//create new SSL BIO, basing on a configured context
	BIO* bio = SSLWrap::BIO_new_ssl_connect(itsCTX);
	if (bio == NULL) {
		throw_SSL("BIO_new_ssl_connect failed");
	}

	//make sure SSL is here
	SSLWrap::BIO_get_ssl_(bio, & itsSSL);
	if (itsSSL == NULL) {
		throw_SSL("BIO_get_ssl failed");
	}

	/* With this option set, if the server suddenly wants a new handshake,
	 * OpenSSL handles it in the background. */
	SSLWrap::SSL_set_mode_(itsSSL, SSL_MODE_AUTO_RETRY);

	/*The hostname can be an IP address. The hostname can also include the port
	 * in the form hostname:port . It is also acceptable to use the form
	 * "hostname/any/other/path" or "hostname:port/any/other/path".*/
	SSLWrap::BIO_set_conn_hostname_(bio, itsSrverAddress.GetHostAndPort().c_str());

	DBG << "populated safe client BIO @host=" << itsSrverAddress.GetHostAndPort() << std::endl;
	SetBIO(bio);

	DBG_CONSTRUCTOR;
}
Example #19
0
bool CKeyboard::HandleMessage( unsigned int uMsg, unsigned int wParam, long lParam )
{
	if( !m_pDialog->IsVisible()|| m_pDialog->GetMouse()->GetLeftButton() )
		return false;

	switch ( uMsg )
	{
		case WM_KEYDOWN:
			SetKey ( SKey ( static_cast< SIMPLEGUI_CHAR >( wParam ), true, lParam ) );
			break;
		case WM_KEYUP:
			SetKey ( SKey ( static_cast< SIMPLEGUI_CHAR >( wParam ), false, lParam ) );
			break;
	}

	return true;//m_pDialog->MsgProc( GetKey() );
}
nsresult
nsDOMStorageDBWrapper::SetKey(DOMStorageImpl* aStorage,
                              const nsAString& aKey,
                              const nsAString& aValue,
                              bool aSecure)
{
  IMPL_FORWARDER(SetKey(aStorage, aKey, aValue, aSecure));
}
Example #21
0
FReply SFlareKeyBind::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
{
	if (bWaitingForKey)
	{
		SetKey(InKeyEvent.GetKey());
		return FReply::Handled();
	}
	return FReply::Unhandled();
}
Example #22
0
static void
FreeThread(void *arg)
{
    Thread *thrPtr = arg;

    /*
     * Restore the current slots during cleanup so handlers can access
     * TLS in other slots.
     */

    SetKey("FreeThread", arg);
    NsCleanupTls(thrPtr->slots);
    SetKey("FreeThread", NULL);
    if (thrPtr->marked) {
	StackPages(thrPtr, 0);
    }
    ns_free(thrPtr);
}
Example #23
0
DockBase::DockBase()
{
	skinindex =	layoutindex = 0;
	tabsicons =	tabsclose =	tabsautoalign = true;
	tabsnested = false;
	autohideicons =	autohideclose = true;
	isready = false;
    panesize.Clear();
    LeftPos(0, 0).TopPos(0,0);
	CtrlLayout(listtab);
	CtrlLayout(grouptab);
    CtrlLayout(controlpanel);
   	controlpanel.CenterScreen().Sizeable().Zoomable().Title(t_("Settings"));
    listtab.list.AddColumn();
    listtab.list.AddColumn(t_("Window Title"));
    listtab.list.AddColumn(t_("Alignment"));
    listtab.list.AddColumn(t_("State"));
    listtab.list.AddColumn(t_("Position"));
    listtab.list.EvenRowColor();
    listtab.list.SetLineCy(16);

	grouptab.grouptree.MultiSelect();
	controlpanel.panel.Add(listtab.SizePos(), t_("Status"));
	controlpanel.panel.Add(grouptab.SizePos(), t_("Group Manager"));

    controlpanel.skinlist.Add(0, String(t_("Default"))).Add(1, String(t_("Classic"))).Add(2, String(t_("Enhanced"))).SetIndex(skinindex);
    controlpanel.skinlist.WhenAction 	= THISBACK(OnSelectSkin);
    controlpanel.layoutlist.WhenAction	= THISBACK(OnSelectLayout);
    listtab.list.WhenLeftClick 			= THISBACK(OnPanelAction); 
    grouptab.grouptree.WhenDropInsert	= THISBACK(GroupDrop);
    grouptab.grouptree.WhenDrag			= THISBACK(GroupDrag);
    grouptab.grouptree.WhenBar			= THISBACK(GroupMenu);
	grouptab.grouptree.WhenCursor		= THISBACK(GroupSelect);
	   
	grouptab.groupadd					<<= THISBACK(OnAddNewGroup);
	grouptab.groupdelete				<<= THISBACK(OnDeleteGroup);
    controlpanel.layoutbutton			<<= THISBACK(ResetWidgetLayout);
	controlpanel.layoutadd				<<= THISBACK(OnAddNewLayout);
	controlpanel.layoutdelete			<<= THISBACK(OnDeleteLayout);
    controlpanel.TabOptionAlignment		<<= THISBACK(RefreshWidgetLayout);
    controlpanel.TabOptionIcon			<<= THISBACK(RefreshWidgetLayout);
    controlpanel.TabOptionClose			<<= THISBACK(RefreshWidgetLayout);
    controlpanel.AutoOptionClose		<<= THISBACK(RefreshWidgetLayout);
    controlpanel.AutoOptionIcon			<<= THISBACK(RefreshWidgetLayout);

	controlpanel.TabOptionIcon 			<<= tabsicons;
	controlpanel.TabOptionClose 		<<= tabsclose;
	controlpanel.TabOptionNest			<<= tabsnested;
	controlpanel.TabOptionAlignment	 	<<= tabsautoalign;

	controlpanel.AutoOptionIcon 		<<= autohideicons;
	controlpanel.AutoOptionClose 		<<= autohideclose;
	
	grouptab.groupdelete.Disable();
	SetKey(K_CTRL_HOME);
}
Example #24
0
FReply SFlareKeyBind::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	if (bWaitingForKey)
	{
		SetKey(MouseEvent.GetWheelDelta() > 0 ? EKeys::MouseScrollUp : EKeys::MouseScrollDown);
		return FReply::Handled();
	}

	return FReply::Unhandled();
}
Example #25
0
void ConfigFile::SetColor(CTSTR lpSection, CTSTR lpKey, const Color4 &color)
{
    if(!bOpen)
        return;

    TCHAR strColor[50];

    tsprintf_s(strColor, 49, TEXT("{%.3f, %.3f, %.3f, %.3f}"), color.x, color.y, color.z, color.w);
    SetKey(lpSection, lpKey, strColor);
}
Example #26
0
void ConfigFile::SetFloat(CTSTR lpSection, CTSTR lpKey, float number)
{
    if(!bOpen)
        return;

    TCHAR strNum[20];

    tsprintf_s(strNum, 19, TEXT("%f"), number);
    SetKey(lpSection, lpKey, strNum);
}
Example #27
0
void ConfigFile::SetHex(CTSTR lpSection, CTSTR lpKey, DWORD number)
{
    if(!bOpen)
        return;

    TCHAR strNum[22] = TEXT("0x");

    itots_s(number, strNum+2, 19, 16);
    SetKey(lpSection, lpKey, strNum);
}
Example #28
0
void ConfigFile::SetInt(CTSTR lpSection, CTSTR lpKey, int number)
{
    if(!bOpen)
        return;

    TCHAR strNum[20];

    itots_s(number, strNum, 19, 10);
    SetKey(lpSection, lpKey, strNum);
}
Example #29
0
void ConfigFile::SetString(CTSTR lpSection, CTSTR lpKey, CTSTR lpString)
{
    if(!bOpen)
        return;

    if(!lpString)
        lpString = TEXT("");

    SetKey(lpSection, lpKey, lpString);
}
Example #30
0
	void GarlicDestination::AddSessionKey (const uint8_t * key, const uint8_t * tag)
	{
		if (key)
		{
			uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
			auto decryption = std::make_shared<i2p::crypto::CBCDecryption>();
			decryption->SetKey (key);
			m_Tags[SessionTag(tag, ts)] = decryption;
		}
	}