客户端库
Github 页面 onetime-ruby 作者:Delano(更新于 2024-06-09)
require 'onetime/api'
api = Onetime::API.new('YOUR_EMAIL', 'YOUR_OTS_APIKEY')options = { secret: 'Jazz, jazz and more jazz.', recipient: 'example@onetimesecret.com', ttl: 7200}
ret = api.post('/share', options)puts ret['secret_key']Python
Section titled “Python”Github 页面 - onetimesecret-cli 作者:slashpass(添加于 2021-07-08)
from onetimesecret import OneTimeSecretCli
cli = OneTimeSecretCli(ONETIMESECRET_USER, ONETIMESECRET_KEY)cli.create_link("secret") # 返回类似 https://onetimesecret.com/secret/xxxxxxxxxxx 的链接Github 页面 - py_onetimesecret 作者:Vladislav Stepanov(添加于 2012-06-26)
from onetimesecret import OneTimeSecret
o = OneTimeSecret("YOUR_EMAIL", "YOUR_OTS_APIKEY")secret = o.share(u"test")
print o.retrieve_secret(secret["secret_key"])# {u'secret_key': u'dtr7ixukiolpx1i4i87kahmhyoy2q65',# u'value': u'test'}CPAN 上的 Net::OneTimeSecret 作者:Kyle Dawkins(添加于 2012-01-06)
#!/usr/bin/env perl
use Net::OneTimeSecret;
# 注意:请替换为您自己的凭据才能正常使用!my $customerId = 'YOUR_EMAIL';my $testApiKey = 'YOUR_OTS_APIKEY';
my $api = Net::OneTimeSecret->new( $customerId, $testApiKey );my $result = $api->shareSecret( 'Jazz, jazz and more jazz.', passphrase => 'thepassword', recipient => 'kyle@shoffle.com', ttl => 7200, );printf( "%s\n", $result->{secret_key} );
my $secret = $api->retrieveSecret( $result->{secret_key}, passphrase => "thepassword" );printf( "%s\n", $secret->{value} );Github 页面 - onetime-java 作者:Marcin Pawlowski(添加于 2014-05-22)
OneTimeSecret ots = new OneTimeSecretRestImpl( "https://path/to/ots/instance", "ots-username", "ots-apikey");
GenerateResponse generateResponse = ots.generate( new GenerateRequest.Builder() .withPassphrase("supersecret") .build());
RetrieveResponse retrieveResponse = ots.retrieve( new RetrieveRequest.Builder() .withSecretKey(shareResponse.getSecretKey()) .withPassphrase("supersecret") .build());
assertEquals(generateResponse.getValue(), retrieveResponse.getValue());Github 页面 - OneTimeSharp 作者:Vladislav Stepanov(添加于 2014-05-29)
# 您可以在任何兼容 .NET (4.0+) 或 Mono (2.10.8+) 的项目中使用 OneTimeSharp。using VStepanov.OneTimeSharp;
class Test{ static void Main(string[] args) { var ots = new OneTimeSecret("YOUR_EMAIL", "YOUR_OTS_APIKEY");
var generated = ots.GenerateSecret();
Console.WriteLine(generated.Value); // LR*?us*A(UT*
Console.WriteLine(generated.SecretKey); // ikzx3m77j5by8411cg5lk5fvfylvl0i Console.WriteLine(ots.GetSecretLink(generated)); // https://onetimesecret.com/secret/ikzx3m77j5by8411cg5lk5fvfylvl0i
var shared = ots.ShareSecret("Hello, OTS!");
Console.WriteLine(shared.MetadataKey); // kd6rgsucl98qbgu9eavjq4k5sdxsom0 Console.WriteLine(ots.GetMetadataLink(shared)); // https://onetimesecret.com/private/kd6rgsucl98qbgu9eavjq4k5sdxsom0 }}Github 页面 - onetimesecret 作者:Corbalt(添加于 2021-12-10)
import ots "github.com/corbaltcode/go-onetimesecret"
client := ots.Client{ Username: "user@example.com", Key: "my api key",}
metadata, err := client.Put("the launch codes", "passphrase", 0, "")if err != nil { // 处理错误}
secret, err := client.Get(metadata.SecretKey, "passphrase")if err != nil { // 处理错误}
// 输出 "the launch codes"print(secret)命令行使用示例
Section titled “命令行使用示例”$ go install github.com/corbaltcode/go-onetimesecret/cmd/ots@latest
$ ots put 'what is essential is invisible to the eye'hdjk6p0ozf61o7n6pbaxy4in8zuq7sm ifipvdpeo8oy6r8ryjbu8y7rhm9kty9
$ ots get hdjk6p0ozf61o7n6pbaxy4in8zuq7smwhat is essential is invisible to the eye
$ ots genrVjbS$twCJkS 4nwhy7v4fnabayqc5auv4ogh0nfr20 flsdlaun6hwczqu9utmc0vts5xj9xu1
$ ots burn flsdlaun6hwczqu9utmc0vts5xj9xu1flsdlaun6hwczqu9utmc0vts5xj9xu1Github 页面 作者:Emídio Neto(添加于 2024-06-09)
// 创建新客户端client := ots.NewClient( WithUsername("otsuser@domain.com"), WithApiKey("xxxxxxxx"),)
// 发送带上下文的请求ctx := context.Background()response, err := client.GetStatus(ctx)if err != nil { panic(err)}
fmt.Println(response.Status)PowerShell
Section titled “PowerShell”Github 页面 - OneTimeSecret 作者:Craig Gumbley(更新于 2017-04-28)
# 从 PowerShell 库安装Install-Module -Name OneTimeSecret -Scope CurrentUser
# 设置连接信息Set-OTSAuthorizationToken -Username user@mail.com -APIKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 生成新的共享密钥New-OTSSharedSecret -Secret "Very Secret" -Passphrase 1234 -Recipient user@mail.com
# 获取密钥Get-OTSSecret -SecretKey qqevnp70b4uoiax4knzhwlhros6ne7x -Passphrase 1234
# 查看所有可用函数Get-Command -Module OneTimeSecret | Select NameGithub 页面 - OneTimeSecret-bash 作者:Eric Engstrom(更新于 2018-12-19)
脚本 API 使用示例
Section titled “脚本 API 使用示例”# 以匿名方式使用(匿名创建密钥)source ots.bash
# 或者使用特定的认证凭据APIUSER="USERNAME"APIKEY="APIKEY"source ots.bash -u $APIUSER -k $APIKEY
# 检查服务器状态ots_status
# 创建密钥并获取 URLURL=$(echo "secret" | ots_share)
# 通过 HEREDOC 分享多行密钥URL=$(ots_share <<-EOF This is a Secret ... on multiple linesEOF)
# 向 share 或 generate 传递选项URL=$(ots_share ttl=600 \ passphrase="shared-secret" \ recipient="someone@somewhere.com" <<< "SECRET")
# 获取密钥数据local DATA="$(ots_retrieve "$URL")"
# 分享/生成新密钥,并获取私有元数据密钥local KEY=$(ots_metashare <<< "SECRET")local KEY=$(ots_metagenerate)
# 获取最近创建的私有元数据密钥列表# 注意:这需要有效的认证凭据local -a RECENT=( $(ots_recent) )
# 检查密钥的当前状态(需提供私有密钥)ots_state $KEY
# 销毁密钥(需提供私有密钥)ots_burn $KEY命令行使用示例
Section titled “命令行使用示例”# 分享密钥(从标准输入)./ots shareSECRET^D
# 分享密钥(通过 HEREDOC)./ots share <<-EOF This is a mulit-line secret via HEREDOC. Somthing else goes here.EOF
# 获取/检索密钥:./ots get <key|url>./ots retrieve <key|url>命令行使用示例
Section titled “命令行使用示例”$ ots burn flsdlaun6hwczqu9utmc0vts5xj9xu1flsdlaun6hwczqu9utmc0vts5xj9xu1