/*
CDpkgConfig* CvSakke::GetSakkeParams() //temporary
{ return CDpkgConfig::Instance(); 
}
*/
bool CvSakke::DecodePublicKey( const String& aPublicKey, OUT octet& aZ_S )
{
	OCTET_CLEAR(&aZ_S);
	
	if ( aPublicKey[0] != '[' || aPublicKey[aPublicKey.length()-1] != ']' )
		return false;
	
	CvString publicKey = aPublicKey;
	
	publicKey.TrimLeft( "[" );
	publicKey.TrimRight( "]" );	
	
	vector<CvString> tokens;
	publicKey.Tokenize( ",", tokens );
	
	if ( tokens.size() != 2 )
		return false;
	
	OCTET_JOIN_BYTE( 4, 1, &aZ_S );
	
	for ( vector<CvString>::const_iterator itr = tokens.begin();
		 itr != tokens.end();
		 ++itr )
	{
		String decoded;

		CvBase64::Decode( *itr, decoded );
		if ( decoded.size() != FS )
			return false;
		OCTET_JOIN_BYTES( decoded.data(), FS, &aZ_S );
	}
	
	return true;
}
bool CvSakke::DecodePrivateKey( const String& aPrivateKey, OUT octet& aKbS )
{
	CMiracl miracl( m_sakkeDomain );
	
	OCTET_CLEAR(&aKbS);
	
	if ( aPrivateKey[0] != '[' || aPrivateKey[aPrivateKey.length()-1] != ']' )
		return false;
	
	CvString privateKey = aPrivateKey;
	
	privateKey.TrimLeft( "[" );
	privateKey.TrimRight( "]" );	
	
	vector<CvString> tokens;
	privateKey.Tokenize( ",", tokens );
	
	if ( tokens.size() != 4 )
		return false;
	
	Big xx, xy, yx, yy;
	Big* pBigs[] = { &xx, &xy, &yx, &yy };
	
	int i = 0;
	for ( vector<CvString>::const_iterator itr = tokens.begin();
		 itr != tokens.end();
		 ++itr, ++i )
	{
		String decoded;
		CvBase64::Decode( *itr, decoded );
		bytes_to_big( _MIPP_ (int)decoded.size(), decoded.data(), pBigs[i]->getbig() );		
	}
	
	ZZn2 x( xx, xy );
	ZZn2 y( yx, yy );
	
	aKbS.len = 4*FS;
	big_to_bytes( _MIPP_ FS, x.getzzn2()->a, &aKbS.val[0], TRUE );
	big_to_bytes( _MIPP_ FS, x.getzzn2()->b, &aKbS.val[FS], TRUE);
	big_to_bytes( _MIPP_ FS, y.getzzn2()->a, &aKbS.val[2*FS], TRUE);
	big_to_bytes( _MIPP_ FS, y.getzzn2()->b, &aKbS.val[3*FS], TRUE);

	return true;
}