在互联网上发送Android市场公钥(Sending Android market public key across the internet)

通过互联网以原始base64形式发送Android Market公钥是否安全? 如果我这样做会遇到什么问题?


Is it safe to send the Android Market public key in raw base64 form across the internet? What problems could I encounter if I did this?


原文:https://stackoverflow.com/questions/4422428
2024-04-23 17:04

满意答案

这是一个使用Observer模式将观察者注册到登录系统的示例。 在示例中,我注册了一个观察者,在创建新用户时向管理员发送电子邮件:

首先,我们创建定义observable / observers行为的接口

interface IObserver
{
     //an observer has to implement a function, that will be called when the observable changes
     //the function receive data (in this case the user name) and also the observable object (since the observer could be observing more than on system)
     function onUserAdded( $observable, $data );
}

interface IObservable
{
    //we can attach observers to the observable
    function attach( $observer );
}

然后让您的主登录系统实现IObservable,实现attach函数,并保留一组观察者。 在内部,您实现了一个notify函数,在调用它时,迭代数组并通知每个观察者。

你做的是,在创建用户的所有正常行为之后,你调用你的通知函数。

class LoginSystem implements IObservable
{
    private $observers = array();

    private function notify( $userName )
    {
        foreach( $this->observers as $o )
            $o->onUserAdded( $this, $userName );
    }

    public function attach( $observer )
    {
        $this->observers []= $observer;
    }

    public function createUser( $userName )
    {

        //all your logic to add it to the databse or whatever, and then:

        $this->notify($userName);

    }

}

然后,您创建一个类而不是实现Iobserver。 在onUserAdded函数中,您可以在发生观察事件时执行任何操作。 在这个例子中,我只是将邮件发送到硬编码的电子邮件。 它可能会像你想要的那样复杂。

class NewUserMailer implements IObserver
{
    public function  onUserAdded( $observable, $data ) 
    {
        mail("admin@yoursite.com", "new user", $data);
    }
}

然后,行为就是在创建登录系统之后,您还创建了一个观察者,并且附加到登录系统

$ls = new LoginSystem();
$ls->attach( new NewUserMailer() );

有了这个,每次创建新用户时,邮件都会发送到“admin@yoursite.com”


This is an example that uses the Observer pattern to register observers to your login system. In the example, i register an observer that sends a email to the admin when a new user is created:

First, we create the interfaces that define the behavior of the observable/observers

interface IObserver
{
     //an observer has to implement a function, that will be called when the observable changes
     //the function receive data (in this case the user name) and also the observable object (since the observer could be observing more than on system)
     function onUserAdded( $observable, $data );
}

interface IObservable
{
    //we can attach observers to the observable
    function attach( $observer );
}

Then you let your main login system implement IObservable, you implement the attach function, and keep an array of observers. internally, you implement a notify function that when it is called, iterate the array and notify every observer.

What you do, is after all the normal behavior of creating an user, you call your notify function.

class LoginSystem implements IObservable
{
    private $observers = array();

    private function notify( $userName )
    {
        foreach( $this->observers as $o )
            $o->onUserAdded( $this, $userName );
    }

    public function attach( $observer )
    {
        $this->observers []= $observer;
    }

    public function createUser( $userName )
    {

        //all your logic to add it to the databse or whatever, and then:

        $this->notify($userName);

    }

}

Then, you create a class than implements Iobserver. in the onUserAdded function, you do whatever you want to happen when the observed event occurs. In this example i just send a mail to a hardcoded email. It could be as complex as you want.

class NewUserMailer implements IObserver
{
    public function  onUserAdded( $observable, $data ) 
    {
        mail("admin@yoursite.com", "new user", $data);
    }
}

Then, the behavior is just, after creating the loginsystem, you also create an observer, and attach is to the login system

$ls = new LoginSystem();
$ls->attach( new NewUserMailer() );

With this, everytime a new user is created, a mail will be sent to "admin@yoursite.com"

相关问答

更多

这段代码是否遵循观察者模式?(Does this code follow Observer pattern?)

那么从技术角度来看,上面给出的代码是否代表观察者模式? 没有 但只是想知道什么构成观察者模式? 我已更新您的代码以模拟观察者模式。 #[allow(unused_variables)] pub trait Events { fn on_value(&self, value: &str) {} } struct Observable { value: String, observers: Vec<Box<Events>>, } impl Observable { f...

如何在PHP中实现完整的Observer模式(How to implement a full Observer pattern in PHP)

观察员实际上并没有与他们正在观察的课程相联系。 观察者的处理程序和观察对象之间的连接使用文字字符串值(例如`upload.error'),这意味着: 如果你想观察一个特定的对象,你必须事先知道它将要发布的事件的名称; 这是你不喜欢的“耦合”。 另一方面,如果您只对特定事件感兴趣,则可以观察该事件的任何类型的对象,而无需了解该对象的任何知识。 上述第2项是您关心的一项好处,但对项目1应该如何处理? 如果你仔细想想,如果它们代表不同的事件发生,就需要有一些方法来区分同一观察者的回调。 无论采取何种形式...

观察者模式的策略?(strategy for observer pattern?)

在支持多重继承的语言中,支持这种功能的对象来自支持这些方法的Observable类的INHERIT并不罕见。 我从来没有遇到过使用聚合来支持这个的解决方案,这就是你所描述的,但鉴于PHP不支持多重继承,这听起来像是一个合理的解决方法。 It's not unusual for an object that supports this functionality to INHERIT from an Observable class, which supports these methods, in...

为什么在观察者模式中使用接口?(Why interface is used in observer pattern?)

在这里,我剥离了java.util.Observable不重要的部分,这是一个为扩展而设计的类,它使用了Observer接口。 这是Java代码,但当然任何OOP语言都可以实现这种模式。 package java.util; public class Observable { private boolean changed = false; private Vector obs; public Observable() { obs = new Vecto...

MVVM本身是Observer模式吗?(Is MVVM itself a Observer pattern?)

MVVM-和Observable-模式是不同的模式,你会发现很多很好的例子。 假设您正在实施MVVM电话应用程序,这两种模式可以很好地结合使用: 您的ViewModel(MV VM )具有要在XAML-VIEW(M V VM)中显示/更新的属性。 无论何时设置(或更新)属性值(在ViewModel中),都会触发类似()=> PropertyChanged("PropertyName); Observer现在位于MVVM Framework(或ViewModel的基类)中,此组件观察这些更改并使用V...

如何在PHP登录系统中使用Observer模式?(How to use the Observer pattern in PHP login system?)

这是一个使用Observer模式将观察者注册到登录系统的示例。 在示例中,我注册了一个观察者,在创建新用户时向管理员发送电子邮件: 首先,我们创建定义observable / observers行为的接口 interface IObserver { //an observer has to implement a function, that will be called when the observable changes //the function receive da...

使用Flash事件系统或构建自己的观察者设计模式?(Use Flash Event System or build own Observer Design Pattern?)

是调度Event很慢,如果您的目标是性能,您可以选择自己的事件系统,或者如果您不想重新发明轮子,请查看Robert Penner的as3信号库 。 Yes dispatching Event are slow, if performance are you goal you can go for your own event system or if you don't want to reinvent the wheel take a look at the as3 signals librar...

Javafx和Observer模式 - 更新UI(Javafx and the Observer pattern - updating a UI)

为了直接回答你的问题,我可能会将Observer实现为控制器中的内部类。 然后它可以访问控制器中的所有内容。 假设这里PhoneBook定义了表单的方法 public List<PhoneNumber> getPhoneNumbers() ; 然后你可以这样做: public class Controller { @FXML private ListView<PhoneNumber> phoneNumberList ; private PhoneBook number...

Observer模式如何减少耦合?(How does the Observer pattern reduce coupling?)

Observer模式减少了参与者之间的耦合,因为它在Subject和Observers之间引入了一个抽象类型Observer。 想象一个模型(四人帮中的主题/维基百科描述,以及业务逻辑的主页)和一个视图(一个观察者)。 如果没有Observer,模型需要在View发生变化时调用方法。 模型将知道View的具体类并与之相关联,以及View所属的任何UI特定框架。 使用Observer,Model只知道Observer的类型(抽象类或接口),因此它没有与具体的View耦合。 The Observer ...

观察者设计模式问题(observer design pattern question)

第二个例子看起来不错,但我不确定是否在OrderItemPickObserver类的update方法中创建新的Position对象。 相反,我建议将Position对象保持为OrderItem类的属性,以便您可以从外部设置它。 class OrderItem extends Observable { private $_position; public function setPosition($position){ $this->_...

相关文章

更多

android 集成所有分享平台

注意: 本文介绍的是Share SDK 2.x版本的集成流程和注意事项,对于Share SDK 1.x ...

《发布Joomla! 网站到互联网:宁皓网》(Launch your Joomla! site to the internet @ ninghao.org)开放式课程[MOV]

中文名: 发布Joomla! 网站到互联网:宁皓网 英文名: Launch your Jooml ...

Android精品软件汇总(不断更新)

用Android手机有一段时间了,发现了不少优秀的软件,在这里向大家推荐一下 1.GTasks:手机上 ...

Android开发_微信分享功能

在你的app应用里增加微信分享的功能,可以分享给好友、朋友圈。 首先,看官方文档这是必须的: 微信An ...

疯狂Android讲义

李刚编著的《疯狂Android讲义》全面地介绍了Android应用开发的相关知识,全书内容覆盖了And ...

Android照片墙应用实现,再多的图片也不怕崩溃

效果如下图所示: 照片墙这种功能现在应该算是挺常见了,在很多应用中你都可以经常看到照片墙的身影。它的设 ...

Android 再多图片也不会出现OOM

照片墙这种功能现在应该算是挺常见了,在很多应用中你都可以经常看到照片墙的身影。它的设计思路其实也非常简 ...

android---TextView赋值问题

private TextView text; @Override protected void o ...

android googlemap问题,求帮助...

地图出现一格一格的叉叉,当执行以下三种情况的时候都会出现这问题 1、移动地图时 2、点击标记时 ...

Android应用加入微信分享

一、申请你的AppID http://open.weixin.qq.com/ 友情提示:推荐使用ec ...

最新问答

更多

sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)

否(它不会使它们无法访问),是(您可以在没有停机的情况下运行它)。 sp_updatestats可以在没有停机的情况下针对实时数据库运行。 No (it doesn't make them inaccessible), and Yes (you can run it without downtime). sp_updatestats can be run against a live database without downtime.

如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)

最终,我们选择了使用Spark Framework for Java实现的后端REST API。 这可能不是最强大的,用户反馈一直是个问题。 我们将命令行界面拆分为提交REST调用,并将结果显示给用户。 Ultimately, we chose to go the route of having a backend REST API that was implemented with the Spark Framework for Java. This may not be the most r

AESGCM解密失败的MAC(AESGCM decryption failing with MAC)

您不能将Encoding.UTF8.GetString应用于任意二进制数据。 它只能解码使用UTF-8编码字符串的结果的字节。 .net实现将默默地破坏数据,而不是默认情况下抛出异常。 您应该使用Base64: Convert.FromBase64String和Convert.ToBase64String You can't apply Encoding.UTF8.GetString to arbitrary binary data. It can only decode bytes that

Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)

我希望能看到更多你的Sass代码等,但我的猜测是你需要在所有嵌套行上使用nest行为。 在我看来,基金会在Sass中的行主要是为了在一个层面上使用。 嵌套在另一行中的任何行都应使用nest行为,除非您希望在列上添加额外的填充。 在你的CodePen中,我能够通过向所有行添加一类collapse来修复列上填充的问题,我认为这与执行$behavior: nest相同$behavior: nest在Sass中$behavior: nest :

湖北京山哪里有修平板计算机的

京山有个联想的专卖店,那里卖平板电脑,地址在中百前面的十字路口右拐 ,他们应该会提供相关的维修服务。

SimplePie问题(SimplePie Problem)

我怀疑由于内容的性质(包含代码),stackoverflow提要不起作用。 我使用许多feed解析器看似“正常”的feed有类似的问题,尽管我最近运气最多的是Zend_Feed。 试试吧 I suspect the stackoverflow feed is not working due to the nature of the content (contains code). I have had similar issues with seemingly "normal" feeds us

在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)

是的,您可以通过getApplicationContext()任意数量的时间(后台任务), getApplicationContext()仅返回应用程序的context 。 Yes, you can pass getApplicationContext() any number of time (Background Tasks ) you want, getApplicationContext() simply returns context of the application.

HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)

这是我最终做的事情: 我无法以这种方式提供完全访问权限,而是在project level folder中设置了一个虚拟HTML页面,该页面单击自身以重定向到位于separate, non-project util folder的HTML文件。 这允许我保留除了那个之外的所有内容,非常小的文件分开但不存在文件访问问题。 Here is what I ended up doing: I wasn't able to provide full access exactly this way, but

为什么我会收到链接错误?(Why do I get a linker error?)

看起来您的编译器错误地将名称引入到全局名称空间中,而不是C ++ 11 3.5 / 7中指定的最内层名称空间( Bushman ): 如果没有找到具有链接的实体的块范围声明来引用某个其他声明,那么该实体是最内层封闭名称空间的成员。 代码按照预期在GCC上编译: http : //ideone.com/PR4KVC 你应该能够通过在构造函数的块作用域中声明它之前(或代替它)在正确的名称空间中声明该函数来解决该bug。 但是,我无法访问您的编译器来测试它。 It looks like your co

如何正确定义析构函数(How to properly define destructor)

在C ++中,你需要手动释放内存。 没有垃圾收集器。 您显然需要在析构函数内手动释放内存。 如果您使用new分配内存,则需要对在deconstructor中使用new分配的每个资源使用delete ,例如: class1::~class1(void) { delete resource1; delete resource2; etc... } In C++ you need to free the memory manually. There's no garbage